Skip to content

Commit 88a5e75

Browse files
Feedback changes
1 parent 17e993b commit 88a5e75

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,30 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
8888
return;
8989
}
9090

91-
// Check if class has already have meaningful description
92-
$isShortDescription = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentEnd, $foundVar, false);
93-
if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescription, $commentStart, $tokens) !== true) {
91+
// Check if class has already have meaningful description after @var tag
92+
$isShortDescriptionAfterVar = $phpcsFile->findNext(T_DOC_COMMENT_STRING, $foundVar + 4, $commentEnd, false,
93+
null,
94+
false);
95+
if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescriptionAfterVar, $commentStart, $tokens) !== true) {
96+
preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', $tokens[($foundVar + 2)]['content'], $varParts);
97+
if ($varParts[1]) {
98+
return;
99+
}
100+
$error = 'Short description duplicates class property name.';
101+
$phpcsFile->addWarning($error, $isShortDescriptionAfterVar, 'AlreadyHaveMeaningFulNameVar');
102+
return;
103+
}
104+
// Check if class has already have meaningful description before @var tag
105+
$isShortDescriptionPreviousVar = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $foundVar, $commentStart, false,
106+
null,
107+
false);
108+
if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescriptionPreviousVar, $commentStart, $tokens) !== true) {
109+
preg_match('`^((?:\|?(?:array\([^\)]*\)|[\\\\\[\]]+))*)( .*)?`i', $tokens[($foundVar + 2)]['content'], $varParts);
110+
if ($varParts[1]) {
111+
return;
112+
}
94113
$error = 'Short description duplicates class property name.';
95-
$phpcsFile->addWarning($error, $isShortDescription, 'AlreadyHaveMeaningFulNameVar');
114+
$phpcsFile->addWarning($error, $isShortDescriptionPreviousVar, 'AlreadyHaveMeaningFulNameVar');
96115
return;
97116
}
98117
}

Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ class Bar {
6363
* Variable name
6464
*/
6565
private $variableName;
66+
67+
/**
68+
* Some more invalid description
69+
*
70+
* @var test
71+
*/
72+
protected $test;
6673
}
6774

6875
class correctlyFormattedClassMemberDocBlock
@@ -81,4 +88,15 @@ class correctlyFormattedClassMemberDocBlock
8188
* @var correctlyFormattedProtectedClassMember
8289
*/
8390
protected $correctlyFormattedProtectedClassMember;
91+
92+
/**
93+
* @var Array|\Foo_BAR
94+
*/
95+
protected $array;
96+
97+
/**
98+
* @var \FOO\BAR\TEST\Class\\FooBarInterface|
99+
* \FooObject_TEST_C
100+
*/
101+
private $testObject;
84102
}

Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function getWarningList()
3131
42 => 1,
3232
49 => 1,
3333
56 => 1,
34-
63 => 1
34+
63 => 1,
35+
68 => 1
3536
];
3637
}
3738
}

0 commit comments

Comments
 (0)