Skip to content
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

Tokens: fix up some PHPCS native token values #3218

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Feb 13, 2021

The values of the PHPCS native token types are normally prefixed with PHPCS_. This wasn't the case for the three most recent additions, T_FN_ARROW as introduced in PHPCS 3.5.3, T_TYPE_UNION and T_PARAM_NAME as will be introduced in PHPCS 3.6.0 (not yet released).

While the change to the value for T_FN_ARROW could be considered a breaking change, it is exceedingly rare for a sniff to use the value of a token constant, so IMO opinion, this is a safe change to make.

As for the other two tokens, as they have not been in a release yet, they can be safely updated no matter what.

The PHPCS native token types are normally prefixed with `PHPCS_`. This wasn't the case for the most recent three additions, `T_FN_ARROW` as introduced in PHPCS 3.5.3, `T_TYPE_UNION` and `T_PARAM_NAME` as will be introduced in PHPCS 3.6.0 (not yet released).

While the change to the value for `T_FN_ARROW` could be considered a breaking change, it is exceedingly rare for a sniff to use the _value_ of a token constant, so IMO opinion, this is a safe change to make.

As for the other two tokens, as they have not been in a release yet, they can be safely updated no matter what.
@jrfnl
Copy link
Contributor Author

jrfnl commented Feb 13, 2021

@gsherwood I think this one should definitely go into 3.6.0. Would you mind milestoning it ?

@gsherwood gsherwood added this to the 3.6.0 milestone Feb 14, 2021
gsherwood added a commit that referenced this pull request Feb 14, 2021
@gsherwood gsherwood merged commit c93066f into squizlabs:master Feb 14, 2021
@gsherwood
Copy link
Member

Well spotted, thanks for fixing those.

Agree that nobody should actually be looking at the value. They are only prefixed like that because PHPUnit (I think) introduced the same tokens with different values at some point in the past and they conflicted with all the existing PHPCS ones, so it was for library compatibility more than anything else.

@jrfnl jrfnl deleted the feature/token-constants-fix-values-x-3 branch February 14, 2021 22:27
@jrfnl
Copy link
Contributor Author

jrfnl commented Feb 14, 2021

Makes sense and all the more relevant now PHPUnit has started using PHP_Parser since PHPUnit 9.3 for code coverage. I already ran into breakage in an external library (PHPCompatibility) caused by PHP_Parser backfilling tokens while the sniff was relying on detecting the combination of PHP/PHPCS by checking defined() for a token constant.

Reason I noticed it now was, that I was getting some weird token names (H_DEFAULT for something in the match WIP PR) as the Tokens::tokenName() method expects the PHPCS_ prefix and removes it to get the name 😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants