diff --git a/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php b/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php index 61c45f5e2e..5b029417da 100644 --- a/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php +++ b/src/Standards/PSR12/Sniffs/Functions/ReturnTypeDeclarationSniff.php @@ -86,7 +86,7 @@ public function process(File $phpcsFile, $stackPtr) } $colon = $phpcsFile->findPrevious(T_COLON, $returnType); - if ($tokens[($colon - 1)]['code'] !== T_CLOSE_PARENTHESIS) { + if (isset($colon, $tokens[($colon - 1)]) === true && $tokens[($colon - 1)]['code'] !== T_CLOSE_PARENTHESIS) { $error = 'There must not be a space before the colon in a return type declaration'; $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($colon - 1), null, true); if ($tokens[$prev]['code'] === T_CLOSE_PARENTHESIS) {