33
44use PHP_CodeSniffer \Files \File ;
55use 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 }
0 commit comments