Skip to content

Commit 93ceb18

Browse files
use of PHPDocFormattingValidator
1 parent 519fc72 commit 93ceb18

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

Magento2/Sniffs/Commenting/ClassPropertyPHPDocFormattingSniff.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use PHP_CodeSniffer\Files\File;
55
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
6+
use PHP_CodeSniffer\Util\Tokens;
67

78
/**
89
* Class ClassPropertyPHPDocFormattingSniff
@@ -22,6 +23,28 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff
2223
T_WHITESPACE,
2324
];
2425

26+
/**
27+
* @var PHPDocFormattingValidator
28+
*/
29+
private $PHPDocFormattingValidator;
30+
31+
/**
32+
* Constructs an AbstractVariableTest.
33+
*/
34+
public function __construct()
35+
{
36+
$scopes = Tokens::$ooScopeTokens;
37+
$this->PHPDocFormattingValidator = new PHPDocFormattingValidator();
38+
$listen = [
39+
T_VARIABLE,
40+
T_DOUBLE_QUOTED_STRING,
41+
T_HEREDOC,
42+
];
43+
44+
parent::__construct($scopes, $listen, true);
45+
46+
}
47+
2548
/**
2649
* @param File $phpcsFile
2750
* @param int $stackPtr
@@ -39,9 +62,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
3962
$phpcsFile->addWarning('Missing class property doc comment', $stackPtr, 'Missing');
4063
return;
4164
}
42-
4365
$commentStart = $tokens[$commentEnd]['comment_opener'];
44-
4566
$foundVar = null;
4667
foreach ($tokens[$commentStart]['comment_tags'] as $tag) {
4768
if ($tokens[$tag]['content'] === '@var') {
@@ -69,9 +90,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
6990

7091
// Check if class has already have meaningful description
7192
$isShortDescription = $phpcsFile->findPrevious(T_DOC_COMMENT_STRING, $commentEnd, $foundVar, false);
72-
if ($tokens[$string]['line'] !== $tokens[$isShortDescription]['line']) {
93+
if ($this->PHPDocFormattingValidator->providesMeaning($isShortDescription, $commentStart, $tokens) !== true) {
7394
$error = 'Variable member already have meaningful name';
74-
$phpcsFile->addWarning($error, $isShortDescription, 'AlreadyMeaningFulNameVar');
95+
$phpcsFile->addWarning($error, $isShortDescription, 'AlreadyHaveMeaningFulNameVar');
7596
return;
7697
}
7798
}

Magento2/Tests/Commenting/ClassPropertyPHPDocFormattingUnitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function getWarningList()
2626
13 => 1,
2727
18 => 1,
2828
23 => 1,
29-
30 => 2,
29+
30 => 1,
3030
34 => 1,
3131
42 => 1,
3232
49 => 1,
33-
56 => 1
33+
56 => 1,
3434
];
3535
}
3636
}

0 commit comments

Comments
 (0)