Commit e536947
committed
AbstractPatternSniff: prevent PHP notice
In a live coding situation, the token triggering the pattern being looked for could be at or near the end of the file.
This could lead to a situation where the pattern could never match anyhow as there are not enough tokens left in the file to match against.
In this situation, the sniff could trigger the following PHP error:
```
Increment on type bool has no effect, this will change in the next major version of PHP in path/to/phpcs/src/Sniffs/AbstractPatternSniff.php on line 627
```
This commit prevents this error by bowing out early if there are not enough tokens in the file under scan to match the pattern.
Tested via the `Squiz.Functions.FunctionDeclaration` sniff via which this issue was discovered.1 parent 68a654f commit e536947
File tree
3 files changed
+15
-0
lines changed- src
- Sniffs
- Standards/Squiz/Tests/Functions
3 files changed
+15
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
419 | 424 | | |
420 | 425 | | |
421 | 426 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
0 commit comments