Skip to content

Commit 0220202

Browse files
dereuromarkclaude
andauthored
Fix scope_opener error for abstract/interface methods (#39)
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 <noreply@anthropic.com>
1 parent 8b6e91e commit 0220202

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

PhpCollective/Sniffs/Commenting/DocBlockSniff.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,23 @@ protected function isFullyTyped(File $phpcsFile, int $stackPtr): bool
201201
}
202202
}
203203

204-
// Check for return type
205-
$hasReturnType = isset($tokens[$stackPtr]['parenthesis_closer']) &&
206-
isset($tokens[$stackPtr]['scope_opener']);
204+
// Check for return type - need parenthesis_closer to find return type
205+
if (!isset($tokens[$stackPtr]['parenthesis_closer'])) {
206+
return false;
207+
}
208+
209+
// For abstract methods or interface methods, there's no scope_opener
210+
// In that case, search until semicolon or end of statement
211+
$searchEnd = $tokens[$stackPtr]['scope_opener'] ?? null;
212+
if ($searchEnd === null) {
213+
// Find the semicolon that ends the method declaration
214+
$searchEnd = $phpcsFile->findNext(T_SEMICOLON, $tokens[$stackPtr]['parenthesis_closer']);
215+
if ($searchEnd === false) {
216+
return false;
217+
}
218+
}
207219

208-
$colonPtr = $phpcsFile->findNext(T_COLON, $tokens[$stackPtr]['parenthesis_closer'], $tokens[$stackPtr]['scope_opener']);
220+
$colonPtr = $phpcsFile->findNext(T_COLON, $tokens[$stackPtr]['parenthesis_closer'], $searchEnd);
209221

210222
if ($colonPtr === false) {
211223
return false; // No return type

0 commit comments

Comments
 (0)