1717class FunctionCommentSniff extends PEARFunctionCommentSniff
1818{
1919
20+ /**
21+ * Whether to skip inheritdoc comments.
22+ *
23+ * @var boolean
24+ */
25+ public $ skipIfInheritdoc = false ;
26+
2027 /**
2128 * The current PHP version.
2229 *
@@ -40,6 +47,12 @@ protected function processReturn(File $phpcsFile, $stackPtr, $commentStart)
4047 $ tokens = $ phpcsFile ->getTokens ();
4148 $ return = null ;
4249
50+ if ($ this ->skipIfInheritdoc === true ) {
51+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
52+ return ;
53+ }
54+ }
55+
4356 foreach ($ tokens [$ commentStart ]['comment_tags ' ] as $ tag ) {
4457 if ($ tokens [$ tag ]['content ' ] === '@return ' ) {
4558 if ($ return !== null ) {
@@ -189,6 +202,12 @@ protected function processThrows(File $phpcsFile, $stackPtr, $commentStart)
189202 {
190203 $ tokens = $ phpcsFile ->getTokens ();
191204
205+ if ($ this ->skipIfInheritdoc === true ) {
206+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
207+ return ;
208+ }
209+ }
210+
192211 foreach ($ tokens [$ commentStart ]['comment_tags ' ] as $ pos => $ tag ) {
193212 if ($ tokens [$ tag ]['content ' ] !== '@throws ' ) {
194213 continue ;
@@ -264,6 +283,12 @@ protected function processParams(File $phpcsFile, $stackPtr, $commentStart)
264283
265284 $ tokens = $ phpcsFile ->getTokens ();
266285
286+ if ($ this ->skipIfInheritdoc === true ) {
287+ if ($ this ->checkInheritdoc ($ phpcsFile , $ stackPtr , $ commentStart ) === true ) {
288+ return ;
289+ }
290+ }
291+
267292 $ params = [];
268293 $ maxType = 0 ;
269294 $ maxVar = 0 ;
@@ -695,4 +720,38 @@ protected function checkSpacingAfterParamName(File $phpcsFile, $param, $maxVar,
695720 }//end checkSpacingAfterParamName()
696721
697722
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+
698757}//end class
0 commit comments