Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions PhpCollective/Sniffs/Commenting/DocBlockSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down