forked from squizlabs/PHP_CodeSniffer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tokenizer/PHP: fix tokenization of the
default
keyword
As per: squizlabs#3326 (comment) > After `PHP::tokenize()`, the `DEFAULT` is still tokenized as `T_DEFAULT`. This causes the `Tokenizer::recurseScopeMap()` to assign it as the `scope_opener` to the `;` semi-colon at the end of the constant declaration, with the class close curly brace being set as the `scope_closer`. > In the `PHP::processAdditional()` method, the `DEFAULT` is subsequently retokenized to `T_STRING` as it is preceded by a `const` keyword, but that is too late. > > The `scope_opener` being set on the semi-colon is what is causing the errors to be displayed for the above code sample. The commit fixes this by: 1. Abstracting the list of `T_STRING` contexts out to a class property. 2. Using the list from the property in all places in the `Tokenizer\PHP` class where keyword tokens are (potentially) being re-tokenized to `T_STRING`, including in the `T_DEFAULT` tokenization code which was added to address the PHP 8.0 `match` expressions. Note: the issue was not introduced by `match` related code, however, that code being there does make it relatively easy now to fix this particular case. While this doesn't address 3336 yes, it is a step towards addressing it and will sort out one of the most common causes for bugs.
- Loading branch information
Showing
1 changed file
with
27 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters