Skip to content

Commit 10d14d0

Browse files
author
Stanislav Idolov
authored
ENGCOM-3326: Optimize code to remove phpmd suppress warnings #17805
2 parents 4fc07d8 + 046bfac commit 10d14d0

File tree

2 files changed

+11
-13
lines changed
  • app/code/Magento

2 files changed

+11
-13
lines changed

app/code/Magento/Customer/Model/Metadata/Form/Text.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ public function extractValue(\Magento\Framework\App\RequestInterface $request)
5252

5353
/**
5454
* @inheritdoc
55-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
56-
* @SuppressWarnings(PHPMD.NPathComplexity)
5755
*/
5856
public function validateValue($value)
5957
{
@@ -66,12 +64,12 @@ public function validateValue($value)
6664
$value = $this->_value;
6765
}
6866

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

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

7775
$errors = $this->validateLength($value, $attribute, $errors);
@@ -80,6 +78,7 @@ public function validateValue($value)
8078
if ($result !== true) {
8179
$errors = array_merge($errors, $result);
8280
}
81+
8382
if (count($errors) == 0) {
8483
return true;
8584
}

app/code/Magento/Eav/Model/Attribute/Data/Text.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ public function extractValue(RequestInterface $request)
5555
*
5656
* @param array|string $value
5757
* @return bool|array
58-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
59-
* @SuppressWarnings(PHPMD.NPathComplexity)
58+
* @throws \Magento\Framework\Exception\LocalizedException
6059
*/
6160
public function validateValue($value)
6261
{
@@ -68,13 +67,13 @@ public function validateValue($value)
6867
$value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());
6968
}
7069

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

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

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

0 commit comments

Comments
 (0)