Skip to content

Commit

Permalink
ENGCOM-3326: Optimize code to remove phpmd suppress warnings #17805
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanislav Idolov authored Nov 1, 2018
2 parents 4fc07d8 + 046bfac commit 10d14d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
11 changes: 5 additions & 6 deletions app/code/Magento/Customer/Model/Metadata/Form/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public function extractValue(\Magento\Framework\App\RequestInterface $request)

/**
* @inheritdoc
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function validateValue($value)
{
Expand All @@ -66,12 +64,12 @@ public function validateValue($value)
$value = $this->_value;
}

if ($attribute->isRequired() && empty($value) && $value !== '0') {
$errors[] = __('"%1" is a required value.', $label);
if (!$attribute->isRequired() && empty($value)) {
return true;
}

if (!$errors && !$attribute->isRequired() && empty($value)) {
return true;
if (empty($value) && $value !== '0') {
$errors[] = __('"%1" is a required value.', $label);
}

$errors = $this->validateLength($value, $attribute, $errors);
Expand All @@ -80,6 +78,7 @@ public function validateValue($value)
if ($result !== true) {
$errors = array_merge($errors, $result);
}

if (count($errors) == 0) {
return true;
}
Expand Down
13 changes: 6 additions & 7 deletions app/code/Magento/Eav/Model/Attribute/Data/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public function extractValue(RequestInterface $request)
*
* @param array|string $value
* @return bool|array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function validateValue($value)
{
Expand All @@ -68,13 +67,13 @@ public function validateValue($value)
$value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());
}

if ($attribute->getIsRequired() && empty($value) && $value !== '0') {
$label = __($attribute->getStoreLabel());
$errors[] = __('"%1" is a required value.', $label);
if (!$attribute->getIsRequired() && empty($value)) {
return true;
}

if (!$errors && !$attribute->getIsRequired() && empty($value)) {
return true;
if (empty($value) && $value !== '0') {
$label = __($attribute->getStoreLabel());
$errors[] = __('"%1" is a required value.', $label);
}

$result = $this->validateLength($attribute, $value);
Expand Down

0 comments on commit 10d14d0

Please sign in to comment.