diff --git a/PhpCollective/Sniffs/Commenting/DocBlockSniff.php b/PhpCollective/Sniffs/Commenting/DocBlockSniff.php index 197b6bc..bd73ead 100644 --- a/PhpCollective/Sniffs/Commenting/DocBlockSniff.php +++ b/PhpCollective/Sniffs/Commenting/DocBlockSniff.php @@ -201,11 +201,23 @@ protected function isFullyTyped(File $phpcsFile, int $stackPtr): bool } } - // Check for return type - $hasReturnType = isset($tokens[$stackPtr]['parenthesis_closer']) && - isset($tokens[$stackPtr]['scope_opener']); + // Check for return type - need parenthesis_closer to find return type + if (!isset($tokens[$stackPtr]['parenthesis_closer'])) { + return false; + } + + // For abstract methods or interface methods, there's no scope_opener + // In that case, search until semicolon or end of statement + $searchEnd = $tokens[$stackPtr]['scope_opener'] ?? null; + if ($searchEnd === null) { + // Find the semicolon that ends the method declaration + $searchEnd = $phpcsFile->findNext(T_SEMICOLON, $tokens[$stackPtr]['parenthesis_closer']); + if ($searchEnd === false) { + return false; + } + } - $colonPtr = $phpcsFile->findNext(T_COLON, $tokens[$stackPtr]['parenthesis_closer'], $tokens[$stackPtr]['scope_opener']); + $colonPtr = $phpcsFile->findNext(T_COLON, $tokens[$stackPtr]['parenthesis_closer'], $searchEnd); if ($colonPtr === false) { return false; // No return type