Closed jrfnl closed 4 months ago
Rebased without changes.
Even though there has been no feedback so far, I am going to merge this PR to improve the chances of people using the master
branch testing this change in hopes of any undesired side-effects being caught before the next release.
Description
This commit adds tokenizer support for DNF types as per the proposal outlined in #387.
This means that:
T_TYPE_OPEN_PARENTHESIS
andT_TYPE_CLOSE_PARENTHESIS
for 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_opener
andparenthesis_closer
token array indexes and the tokens between them will have thenested_parenthesis
index.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.static
keyword for properties is still tokenized asT_STATIC
, even when right before a DNF type (which could be confused for a function call).T_FN
with aT_FN_ARROW
scope 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
,true
orfalse
, when used in DNF types are still tokenized to their own token and not tokenized asT_STRING
.array
keyword when used in DNF types is still tokenized asT_STRING
and not asT_ARRAY
.?
intended as an (illegal) nullability operator in combination with a DNF type is still tokenized asT_NULLABLE
and 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