Skip to content

Commit 3fb9cba

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

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,21 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
131131
return;
132132
}
133133

134-
$regularExpression = '/
135-
# Split camelCase "words". Two global alternatives. Either g1of2:
136-
(?<=[a-z]) # Position is after a lowercase,
137-
(?=[A-Z]) # and before an uppercase letter.
138-
| (?<=[A-Z]) # Or g2of2; Position is after uppercase,
139-
(?=[A-Z][a-z]) # and before upper-then-lower case.
140-
/x';
141-
$varTagParts = preg_split($regularExpression, $tokens[$string]['content']);
142-
143-
if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $varTagParts)) !== false) {
134+
$propertyNamePosition = $phpcsFile->findNext(
135+
T_VARIABLE,
136+
$foundVar,
137+
null,
138+
false,
139+
null,
140+
false
141+
);
142+
if ($propertyNamePosition === false) {
143+
return;
144+
};
145+
$propertyName = trim($tokens[$propertyNamePosition]['content'], '$');
146+
$propertyNameParts = array_filter(preg_split('/(?=[A-Z])/', $propertyName));
147+
148+
if (stripos($tokens[$isShortDescriptionPreviousVar]['content'], implode('', $propertyNameParts)) !== false) {
144149
$error = 'Short description duplicates class property name.';
145150
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningfulNameVar');
146151
}

0 commit comments

Comments
 (0)