PHP 8.2 | Tokenizer/PHP: add support for DNF types #461
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This commit adds tokenizer support for DNF types as per the proposal outlined in #387.
This means that:
T_TYPE_OPEN_PARENTHESISandT_TYPE_CLOSE_PARENTHESISfor the parentheses used in DNF types. This allows for sniffs to specifically target those tokens and prevents sniffs which are looking for the "normal" open/close parenthesis tokens from acting on DNF parentheses.parenthesis_openerandparenthesis_closertoken array indexes and the tokens between them will have thenested_parenthesisindex.Based on the currently added tests, the commit safeguards that:
|in types is still tokenized asT_TYPE_UNION, even in DNF types.&in types is still tokenized asT_TYPE_INTERSECTION, even in DNF types.statickeyword for properties is still tokenized asT_STATIC, even when right before a DNF type (which could be confused for a function call).T_FNwith aT_FN_ARROWscope opener is handled correctly, even when DNF types are involved and including when the arrow function is declared to return by reference.self,parent,static,trueorfalse, when used in DNF types are still tokenized to their own token and not tokenized asT_STRING.arraykeyword when used in DNF types is still tokenized asT_STRINGand not asT_ARRAY.?intended as an (illegal) nullability operator in combination with a DNF type is still tokenized asT_NULLABLEand not asT_INLINE_THEN.T_TYPE_OPEN_PARENTHESIS.Includes ample unit tests.
Even so, strenuous testing of this PR is recommended as there are so many moving parts involved, it is very easy for something to have been overlooked.
Suggested changelog entry
Added: tokenizer support for Disjunctive Normal Form types.
Related issues/external references
Related to #105
Closes #387
Closes squizlabs/PHP_CodeSniffer#3731
Types of changes