Commit 6be4ea7
committed
Generic/InlineControlStructure: fix unchecked findNext() return value
On line 67, `findNext()` searches for the first non-empty token after
a `T_ELSE` to detect the `else if` pattern. When `else` is the last
non-empty token in the file (live coding/parse error), `findNext()`
returns `false`. This `false` value was used directly as an array
index on line 68 (`$tokens[$next]`), which silently becomes
`$tokens[0]`, reading the `T_OPEN_TAG` token instead. The bug was silent
because the code would eventually bail out at line 81-83.
This commit adds a `$next === false` check, which also allows the
sniff to bail out earlier for an `else` at end of file instead of
continuing to do unnecessary work before reaching the existing live
coding bail-out further down.
Existing test file InlineControlStructureUnitTest.12.inc already
covers this scenario.1 parent 960d09c commit 6be4ea7
File tree
1 file changed
+1
-1
lines changed- src/Standards/Generic/Sniffs/ControlStructures
1 file changed
+1
-1
lines changedLines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
68 | | - | |
| 68 | + | |
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| |||
0 commit comments