Skip to content

Commit 080bc06

Browse files
jrfnlkukulich
authored andcommitted
TypeHints/DisallowMixedTypeHint: fix logic error
If a file only contains a placeholder docblock (typically an empty `index.php` file in a OS project which doesn't have control over server configuration), it is possible for the `TokenHelper::findNextEffective()` method to return `null`. As the code didn't take this into account, this led to the following error: ``` 1 | ERROR | [ ] An error occurred during processing; checking has been aborted. The error message was: Undefined array | | key "" in | | path/to/SlevomatCodingStandard/Sniffs/TypeHints/DisallowMixedTypeHintSniff.php on | | line 87 | | The error originated in the SlevomatCodingStandard.TypeHints.DisallowMixedTypeHint sniff on line 86. | | (Internal.Exception) ```
1 parent 1136fb9 commit 080bc06

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

SlevomatCodingStandard/Sniffs/TypeHints/DisallowMixedTypeHintSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private function targetHasOverrideAttribute(File $phpcsFile, int $docCommentOpen
8383
$tokens = $phpcsFile->getTokens();
8484
$nextPointer = TokenHelper::findNextEffective($phpcsFile, $docCommentOpenPointer + 1);
8585

86-
if ($tokens[$nextPointer]['code'] !== T_ATTRIBUTE) {
86+
if ($nextPointer === null || $tokens[$nextPointer]['code'] !== T_ATTRIBUTE) {
8787
return false;
8888
}
8989

tests/Sniffs/TypeHints/data/disallowMixedTypeHintNoErrors.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ public function foo(array $mixed)
4747
}
4848

4949
}
50+
51+
/**
52+
* This MUST be the last docblock in the test file and there must not be any code
53+
* after this line for the test to be valid.
54+
*/

0 commit comments

Comments
 (0)