Skip to content

Commit d238849

Browse files
committed
Fixed wrongly returning error for valid descriptions
1 parent 3fb9cba commit d238849

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,16 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
143143
return;
144144
};
145145
$propertyName = trim($tokens[$propertyNamePosition]['content'], '$');
146+
147+
if (strtolower($tokens[$isShortDescriptionPreviousVar]['content']) === strtolower($propertyName)) {
148+
$error = 'Short description duplicates class property name.';
149+
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
150+
return;
151+
}
152+
146153
$propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName));
147154

148-
if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $propertyNameParts)) !== false) {
155+
if (strtolower($tokens[$isShortDescriptionPreviousVar]['content']) === strtolower(implode(' ', $propertyNameParts))) {
149156
$error = 'Short description duplicates class property name.';
150157
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
151158
}

Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,7 @@ class Bar {
6565
private $variableName;
6666

6767
/**
68-
* Some more invalid description with test which is the same name as the variable and is not allowed
69-
*
70-
* @var test
71-
*/
72-
protected $test;
73-
74-
/**
75-
* Formatted Correctly Protected Class Member
68+
* Correctly Formatted Protected Class Member
7669
*
7770
* @var correctlyFormattedProtectedClassMember
7871
*/
@@ -120,4 +113,11 @@ class correctlyFormattedClassMemberDocBlock
120113
* @var RulePool
121114
*/
122115
protected $rulePool;
116+
117+
/**
118+
* A description that includes test which is the same name as the variable is allowed
119+
*
120+
* @var test
121+
*/
122+
protected $test;
123123
}

Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function getWarningList()
3333
56 => 1,
3434
63 => 1,
3535
68 => 1,
36-
82 => 1,
36+
75 => 1,
3737
];
3838
}
3939
}

0 commit comments

Comments
 (0)