@@ -48,11 +48,8 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
48
48
$ return = null ;
49
49
50
50
if ($ this ->skipIfInheritdoc === true ) {
51
- for ($ i = $ commentStart ; $ i <= $ tokens [$ commentStart ]['comment_closer ' ]; $ i ++) {
52
- $ trimmedContent = strtolower (trim ($ tokens [$ i ]['content ' ]));
53
- if ($ trimmedContent === '{@inheritdoc} ' ) {
54
- return ;
55
- }
51
+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
52
+ return ;
56
53
}
57
54
}
58
55
@@ -206,11 +203,8 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart)
206
203
$ tokens = $ phpcsFile ->getTokens ();
207
204
208
205
if ($ this ->skipIfInheritdoc === true ) {
209
- for ($ i = $ commentStart ; $ i <= $ tokens [$ commentStart ]['comment_closer ' ]; $ i ++) {
210
- $ trimmedContent = strtolower (trim ($ tokens [$ i ]['content ' ]));
211
- if ($ trimmedContent === '{@inheritdoc} ' ) {
212
- return ;
213
- }
206
+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
207
+ return ;
214
208
}
215
209
}
216
210
@@ -290,11 +284,8 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
290
284
$ tokens = $ phpcsFile ->getTokens ();
291
285
292
286
if ($ this ->skipIfInheritdoc === true ) {
293
- for ($ i = $ commentStart ; $ i <= $ tokens [$ commentStart ]['comment_closer ' ]; $ i ++) {
294
- $ trimmedContent = strtolower (trim ($ tokens [$ i ]['content ' ]));
295
- if ($ trimmedContent === '{@inheritdoc} ' ) {
296
- return ;
297
- }
287
+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
288
+ return ;
298
289
}
299
290
}
300
291
@@ -729,4 +720,38 @@ protected function checkSpacingAfterParamName(File $phpcsFile, $param, $maxVar,
729
720
}//end checkSpacingAfterParamName()
730
721
731
722
723
+ /**
724
+ * Determines whether the whole comment is an inheritdoc comment.
725
+ *
726
+ * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
727
+ * @param int $stackPtr The position of the current token
728
+ * in the stack passed in $tokens.
729
+ * @param int $commentStart The position in the stack where the comment started.
730
+ *
731
+ * @return void
732
+ */
733
+ protected function checkInheritdoc (File $ phpcsFile , $ stackPtr , $ commentStart )
734
+ {
735
+ $ tokens = $ phpcsFile ->getTokens ();
736
+
737
+ $ allowedTokens = [
738
+ T_DOC_COMMENT_OPEN_TAG ,
739
+ T_DOC_COMMENT_WHITESPACE ,
740
+ T_DOC_COMMENT_STAR ,
741
+ ];
742
+ for ($ i = $ commentStart ; $ i <= $ tokens [$ commentStart ]['comment_closer ' ]; $ i ++) {
743
+ if (in_array ($ tokens [$ i ]['code ' ], $ allowedTokens ) === false ) {
744
+ $ trimmedContent = strtolower (trim ($ tokens [$ i ]['content ' ]));
745
+
746
+ if ($ trimmedContent === '{@inheritdoc} ' ) {
747
+ return true ;
748
+ } else {
749
+ return false ;
750
+ }
751
+ }
752
+ }
753
+
754
+ }//end checkInheritdoc()
755
+
756
+
732
757
}//end class
0 commit comments