-
-
Notifications
You must be signed in to change notification settings - Fork 521
ConstantsHelper::is_use_of_global_constant(): do not treat use const
alias as global constant usage
#2579
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
base: develop
Are you sure you want to change the base?
ConstantsHelper::is_use_of_global_constant(): do not treat use const
alias as global constant usage
#2579
Conversation
…` alias as global constant usage This method was incorrectly identifying a constant alias as a global constant. This change aligns this method with how the sibling method in PHPCompatibility behaves (https://github.com/PHPCompatibility/PHPCompatibility/blob/6e10469b0f3827862b37df2ac2b7ec4580ce888f/PHPCompatibility/Helpers/MiscHelper.php#L45).
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.
Probably a good idea to double-check why that test what added (did it come from the Theme Review sniff and if so, was it added there for a specific reason ?)
I can imagine the reasoning was something along the lines of "we don't track import use statements, so having an alias to one of the discouraged constants will be confusing for humans (they see the constant in the code, think it's the WP constant, turns out it's a different constant) as well as for the sniff itself, as if the sniff would not flag the alias, but it would flag usages of the alias, it would flag something which isn't discouraged"
If this does get merged, I would like to see a comment in the test case file on line 64 documenting that the test would now be a "no false positives" test.
That is a good point. After seeing your comment, I checked the original issue and PR in the The original implementation of the sniff in that repository did not contain a test for a constant alias: https://github.com/WPTT/WPThemeReview/pull/30/files#diff-e0de8e3cd4545002e7d00b32b1ebe749aa609f4b0435ce825fc86e1878cff5a4 And it still did not contain such a test when the sniff was removed from the My best guess is that this test was added to the sniff when you introduced a new version to this repository, including more tests: 80faf1d#diff-bbe0c6d3ccadb9e75fa5ba2b7dce49ee94c6705c55f93d99650517d55c86babaR66.
That is a fair point, and something I hadn't considered. I was only thinking that the sniff should not treat
I'm unsure if I understand your suggestion. I added a comment to the test, highlighting that now the code on line 64 does not trigger an error, even though, for historical reasons, it is in a block where all other code examples do trigger the sniff. Is this more or less what you had in mind? |
Considering I introduced this (even though, I did it when I was much less experienced) and that I can still come up with a reason why it may be good to continue flagging this, I believe a second opinion is warranted on this issue. @GaryJones @dingo-d Either of you have an opinion on the above ? |
What other sniffs tests are using this helper? Can you determine if the constant alias should continue to be flagged in them? |
@GaryJones, besides WordPress-Coding-Standards/WordPress/Sniffs/Security/EscapeOutputSniff.php Lines 577 to 583 in afcb17e
It uses this method when checking if a given code needs to be escaped to bail when it finds a predetermined list of safe PHP constants. Example:
I don't see a reason to continue flagging constant aliases for this specific sniff. |
I'm struggling to comprehend exactly what's being proposed here - @dingo-d I'll let you be the tie-breaker if needed. |
Tbh I am not sure anybody is still using WPThemeReview sniffs (the standard hasn't been updated in 4 years from what I can see). I'd like to see if there is anybody from the themes team still using this when checking themes on .org. To me, it's ok to fix the 'faulty' behavior here, and then make exceptions downstream (in WPThemeReview for example). I'm also having a hard time understanding why this was added (let alone trying to understand what was done back in 2016 🙈 ). |
ConstantsHelper::is_use_of_global_constant()
was incorrectly identifying a constant alias as a global constant.