From 38fb7c209711976f506061b0f7432d9ce2ed19fa Mon Sep 17 00:00:00 2001 From: mscherer Date: Thu, 27 Nov 2025 13:10:52 +0100 Subject: [PATCH] Fix scope_opener error for abstract/interface methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The isFullyTyped() method would crash with "Undefined array key scope_opener" when analyzing abstract methods or interface methods, which don't have a scope_opener token. This fix handles the case by searching for the method's semicolon instead when no scope_opener exists. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../Sniffs/Commenting/DocBlockSniff.php | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) 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