17
17
class FunctionCommentSniff extends PEARFunctionCommentSniff
18
18
{
19
19
20
+ /**
21
+ * Whether to skip inheritdoc comments.
22
+ *
23
+ * @var boolean
24
+ */
25
+ public $ skipIfInheritdoc = false ;
26
+
20
27
/**
21
28
* The current PHP version.
22
29
*
@@ -40,6 +47,12 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
40
47
$ tokens = $ phpcsFile ->getTokens ();
41
48
$ return = null ;
42
49
50
+ if ($ this ->skipIfInheritdoc === true ) {
51
+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
52
+ return ;
53
+ }
54
+ }
55
+
43
56
foreach ($ tokens [$ commentStart ]['comment_tags ' ] as $ tag ) {
44
57
if ($ tokens [$ tag ]['content ' ] === '@return ' ) {
45
58
if ($ return !== null ) {
@@ -189,6 +202,12 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart)
189
202
{
190
203
$ tokens = $ phpcsFile ->getTokens ();
191
204
205
+ if ($ this ->skipIfInheritdoc === true ) {
206
+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
207
+ return ;
208
+ }
209
+ }
210
+
192
211
foreach ($ tokens [$ commentStart ]['comment_tags ' ] as $ pos => $ tag ) {
193
212
if ($ tokens [$ tag ]['content ' ] !== '@throws ' ) {
194
213
continue ;
@@ -264,6 +283,12 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
264
283
265
284
$ tokens = $ phpcsFile ->getTokens ();
266
285
286
+ if ($ this ->skipIfInheritdoc === true ) {
287
+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
288
+ return ;
289
+ }
290
+ }
291
+
267
292
$ params = [];
268
293
$ maxType = 0 ;
269
294
$ maxVar = 0 ;
@@ -695,4 +720,38 @@ protected function checkSpacingAfterParamName(File $phpcsFile, $param, $maxVar,
695
720
}//end checkSpacingAfterParamName()
696
721
697
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 boolean TRUE if the docblock contains only {@inheritdoc} (case-insensitive).
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
+
698
757
}//end class
0 commit comments