From c60acbef66f0182696cf757641d7ffbd653ee07c Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Fri, 23 Jan 2026 13:10:51 -0400 Subject: [PATCH] Update sniff to not add param comments when inheritdoc is found --- .../AddMissingParamTypeFromCallsSniff.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingParamTypeFromCallsSniff.php b/phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingParamTypeFromCallsSniff.php index cf52152318..d0ee8a4bcd 100644 --- a/phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingParamTypeFromCallsSniff.php +++ b/phpcs-sniffs/Formidable/Sniffs/Commenting/AddMissingParamTypeFromCallsSniff.php @@ -81,6 +81,11 @@ public function process( File $phpcsFile, $stackPtr ) { $existingParams = array(); if ( $hasDocblock ) { + // Skip if docblock contains {@inheritdoc}. + if ( $this->hasInheritdoc( $phpcsFile, $docblock ) ) { + return; + } + // Get existing @param tags with their types. $existingParams = $this->getExistingParamTags( $phpcsFile, $docblock ); } @@ -207,6 +212,36 @@ private function findDocblock( File $phpcsFile, $stackPtr ) { return false; } + /** + * Check if a docblock contains {@inheritdoc}. + * + * @param File $phpcsFile The file being scanned. + * @param int $docblock The docblock opener position. + * + * @return bool + */ + private function hasInheritdoc( File $phpcsFile, $docblock ) { + $tokens = $phpcsFile->getTokens(); + + if ( ! isset( $tokens[ $docblock ]['comment_closer'] ) ) { + return false; + } + + $closer = $tokens[ $docblock ]['comment_closer']; + + for ( $i = $docblock; $i < $closer; $i++ ) { + if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_TAG && stripos( $tokens[ $i ]['content'], '@inheritdoc' ) !== false ) { + return true; + } + + if ( $tokens[ $i ]['code'] === T_DOC_COMMENT_STRING && stripos( $tokens[ $i ]['content'], '{@inheritdoc}' ) !== false ) { + return true; + } + } + + return false; + } + /** * Get function parameters. *