-
-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHP 8.4 | Add tokenization of asymmetric visibility #871
base: master
Are you sure you want to change the base?
PHP 8.4 | Add tokenization of asymmetric visibility #871
Conversation
Tests need to pass on PHP 5 where `string` wasn't reserved yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DanielEScherzer Awesome work on this !
I have left a few comments and questions in-line, but generally speaking, this is looking great!
One additional question: how did you determine where in the (huge) PHP::tokenize()
method, the polyfill should go ?
It is currently between the tokenization blocks for T_ENUM_CASE
and PHP 8.0 namespaced names handling.
Is there a particular reason for that ?
&& in_array($token[0], [T_PUBLIC, T_PROTECTED, T_PRIVATE], true) === true | ||
&& ($stackPtr + 3) < $numTokens | ||
&& $tokens[($stackPtr + 1)] === '(' | ||
&& $tokens[($stackPtr + 2)][0] === T_STRING |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& $tokens[($stackPtr + 2)][0] === T_STRING | |
&& is_array($tokens[($stackPtr + 2)]) === true | |
&& $tokens[($stackPtr + 2)][0] === T_STRING |
T_PRIVATE_SET => T_PRIVATE_SET, | ||
T_PROTECTED => T_PROTECTED, | ||
T_PROTECTED_SET => T_PROTECTED_SET, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this is correct... Should these "keywords" ever be changed into T_STRING
depending on their context.... ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is missing some tests to safeguard that invalid code is not affected by this polyfill.
Some suggestions, but feel free to get creative:
// Not valid as asym visibility in PHP 8.4.
public(unset) string $pubx;
public ( set ) string $pubx;
protected/*comment*/ ( set ) string $pubx;
Private{set} string $pubx;
public() string $pubx;
function public(Set $setter) {}
// Live coding test. Needs to be in a file of its own or at the end of the file without a new line after it (and this should be annotated as such to prevent someone adding that new line).
public(set
T_PROTECTED => T_PROTECTED, | ||
T_PUBLIC_SET => T_PUBLIC_SET, | ||
T_PROTECTED_SET => T_PROTECTED_SET, | ||
T_PRIVATE_SET => T_PRIVATE_SET, | ||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you done any tests how this change will affect pre-existing sniffs which use this token array ?
And if it affects pre-existing sniffs, should those be updated in the same PR to not leave those sniffs in a broken state ?
Description
Set up tokenization of asymmetric visibility modifiers:
T_PUBLIC_SET
,T_PROTECTED_SET
, andT_PRIVATE_SET
if not already definedPHP_CodeSniffer\Util\Tokens::$scopeModifiers
)PHP_CodeSniffer\Util\Tokens::$contextSensitiveKeywords
)PHP_CodeSniffer\Tokenizers\PHP::$knownLengths
)Suggested changelog entry
PHP 8.4 | Support tokenization of asymmetric visibility modifiers
Related issues/external references
Related to #851
Types of changes
PR checklist