From 55e415ab9bb2ee061c326a767b3ef06c4cb332ba Mon Sep 17 00:00:00 2001 From: mscherer Date: Fri, 27 Mar 2026 09:43:11 +0100 Subject: [PATCH] Fix InlineDocBlockSniff for abstract/interface methods - Skip methods without a body (abstract/interface) to avoid scanning wrong token ranges that led to false "Invalid Inline Doc Block" errors - Use scope_opener directly instead of searching for curly bracket - Fix hasReturnAsFollowingToken to use === false instead of !$var --- .../Sniffs/Commenting/InlineDocBlockSniff.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/PhpCollective/Sniffs/Commenting/InlineDocBlockSniff.php b/PhpCollective/Sniffs/Commenting/InlineDocBlockSniff.php index c52995a..a69b582 100644 --- a/PhpCollective/Sniffs/Commenting/InlineDocBlockSniff.php +++ b/PhpCollective/Sniffs/Commenting/InlineDocBlockSniff.php @@ -32,8 +32,14 @@ public function register(): array public function process(File $phpcsFile, $stackPointer): void { $tokens = $phpcsFile->getTokens(); - $startIndex = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPointer + 1); - if (!$startIndex || empty($tokens[$startIndex]['bracket_closer'])) { + + // Skip abstract methods and interface methods (no body) + if (empty($tokens[$stackPointer]['scope_opener'])) { + return; + } + + $startIndex = $tokens[$stackPointer]['scope_opener']; + if (empty($tokens[$startIndex]['bracket_closer'])) { return; } @@ -231,7 +237,7 @@ protected function findErrors(File $phpcsFile, int $contentIndex, bool $isSingle protected function hasReturnAsFollowingToken(File $phpcsFile, int $contentIndex): bool { $nextIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $contentIndex + 1, null, true); - if (!$nextIndex) { + if ($nextIndex === false) { return false; }