3
3
4
4
use PHP_CodeSniffer \Files \File ;
5
5
use PHP_CodeSniffer \Sniffs \AbstractVariableSniff ;
6
+ use PHP_CodeSniffer \Util \Tokens ;
6
7
7
8
/**
8
9
* Class ClassPropertyPHPDocFormattingSniff
@@ -22,6 +23,28 @@ class ClassPropertyPHPDocFormattingSniff extends AbstractVariableSniff
22
23
T_WHITESPACE ,
23
24
];
24
25
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
+
25
48
/**
26
49
* @param File $phpcsFile
27
50
* @param int $stackPtr
@@ -39,9 +62,7 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
39
62
$ phpcsFile ->addWarning ('Missing class property doc comment ' , $ stackPtr , 'Missing ' );
40
63
return ;
41
64
}
42
-
43
65
$ commentStart = $ tokens [$ commentEnd ]['comment_opener ' ];
44
-
45
66
$ foundVar = null ;
46
67
foreach ($ tokens [$ commentStart ]['comment_tags ' ] as $ tag ) {
47
68
if ($ tokens [$ tag ]['content ' ] === '@var ' ) {
@@ -69,9 +90,9 @@ public function processMemberVar(File $phpcsFile, $stackPtr)
69
90
70
91
// Check if class has already have meaningful description
71
92
$ 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 ) {
73
94
$ error = 'Variable member already have meaningful name ' ;
74
- $ phpcsFile ->addWarning ($ error , $ isShortDescription , 'AlreadyMeaningFulNameVar ' );
95
+ $ phpcsFile ->addWarning ($ error , $ isShortDescription , 'AlreadyHaveMeaningFulNameVar ' );
75
96
return ;
76
97
}
77
98
}
0 commit comments