|
Ran
|
Jobs
8
|
Files
265
|
Run time
1min
|
Badge
README BADGES
|
push
github
Tokenizer/PHP: fix tokenizer error for a line comment before a ternary colon (#1448) As things were, when a `//` or `#` line comment sits directly before the `:` of a ternary, with the comment on its own line and the `:` on the following line without indentation, tokenizing the file aborts on PHP 8+ with `An error occurred during processing; checking has been aborted. The error message was: `Trying to access array offset on null` pointing into `src/Tokenizers/PHP.php`. The tokenization itself would be correct though. Additionally, when a closure/fn declaration with a return type would be in the "then" part and there would be an inline comment between the keyword and the open parenthesis of the function, both the return type colon, as well as the ternary else colon would be tokenized incorrectly. And PHP would also thrown a warning for `Trying to access array offset on null`. This is related to the PHP 8.0 tokenization change for trailing new lines at the end of inline comments, which the PHPCS tokenizer "undoes". As part of that the original new line token entry is blanked out to `null`. And while the main tokenizer loop skips those `null` entries, various subsections in the tokenizer do their own backward walking in the token stream and can still run into these `null` entries. This commit fixes this for the code related to the inline else tokenization and adds tests to safeguard each of the situations outlined above. Notes: * Within this same section of the `PHP` class, there is [one additional backward walking `for` loop](https://github.com/andrewnicols/PHP_CodeSniffer/blob/e023fad5f/src/Tokenizers/PHP.php#L2627-L2636). As that loop only checks for explicit token values and doesn't try to check if the token is an array or attempt array access of the token, the extra condition should not be necessary. * As for the tests - While mosts of the new tests do not fail without the change, they do throw warnings, which wou... (continued)
6 of 6 new or added lines in 1 file covered. (100.0%)
19891 of 25184 relevant lines covered (78.98%)
99.16 hits per line
| Coverage | ∆ | File | Lines | Relevant | Covered | Missed | Hits/Line |
|---|