-
Notifications
You must be signed in to change notification settings - Fork 38
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
Theme Restricted Parameter #80
Theme Restricted Parameter #80
Conversation
|
||
foreach ( $checks as $key => $check ) { | ||
if ( trim( $token['content'], '\"\'"' ) === $key ) { | ||
$nextStackPtr = $stackPtr; |
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.
Is this line needed?
foreach ( $checks as $key => $check ) { | ||
if ( trim( $token['content'], '\"\'"' ) === $key ) { | ||
$nextStackPtr = $stackPtr; | ||
$nextStackPtr = $phpcsFile->findNext( $types , $nextStackPtr + 1 ); |
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.
Perhaps just place array( T_CONSTANT_ENCAPSED_STRING )
directly in here.
if ( trim( $token['content'], '\"\'"' ) === $key ) { | ||
$nextStackPtr = $stackPtr; | ||
$nextStackPtr = $phpcsFile->findNext( $types , $nextStackPtr + 1 ); | ||
foreach ( $check as $key2 => $arg ) { |
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.
What about $args_key
instead?
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.
Are numbers as bad as globals :)
Will fix in the next update.
563cd1d
to
6671823
Compare
); | ||
|
||
foreach ( $checks as $key => $check ) { | ||
if ( trim( $token['content'], '\"\'"' ) === $key ) { |
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.
Functions in PHP can be uppercase too. So BlogInfo()
would work too. The check would not catch that.
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.
Actually, functions in PHP are case-insensitive, no matter how the function was declared and whether it is a native PHP function or a user-land function.
So any comparison for function names should be done in a case-insensitive way.
function my_function() {
// do something
}
my_function(); // works
MY_function(); // works
MY_FUNCTION(); // works
My_FuncTion(); // works
I suggest pausing work on this one in anticipation of the AbstractFunctionCall base class as discussed in Slack.
|
|
||
if ( isset( $this->functions[ $token['content'] ] ) ) { | ||
$function = $this->functions[ $token['content'] ]; | ||
$parameter_arg = $this->getFunctionCallParameter( $phpcsFile, $stackPtr, 1 ); |
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.
Quick remark: I would make the parameter position part of the array above as for different functions, the parameter position might be different and hardcoding it to 1
here does not allow for that flexibility.
See these example sniffs which also uses this utility function:
- https://github.com/wimg/PHPCompatibility/blob/master/Sniffs/PHP/NewFunctionParametersSniff.php
- https://github.com/wimg/PHPCompatibility/blob/master/Sniffs/PHP/RemovedFunctionParametersSniff.php
- https://github.com/wimg/PHPCompatibility/blob/master/Sniffs/PHP/RequiredOptionalFunctionParametersSniff.php
The array for WP would look differently, but you can probably get some inspiration from the array as used there.
Not all of the parameters are actually deprecated. So I am checking if there is a reason why they were not supposed to be used. https://wordpress.slack.com/archives/core/p1479063392002489 Also it seems like |
Some of the URL ones are not technically deprecated. However, they are inconsistent. Just look at this mess:
IIRC, once core WP added getter functions for the URLs, we decided to make them required for consistency sake. I'd actually like to see core WP drop the entire function and separate it into multiple functions. It might be worth exploring putting a core ticket for that together as a team. |
Ok, I move the parameters that are not deprecated to a restricted parameters sniff so that there is a clear distinction.
Sounds like a good idea. |
Verify restrictions and alts against TRT handbook. |
I will review the actual logic in the |
I will also rebase the PR & update for PHPCS 3.x. |
I would like to finish this one if I could please. |
Looks like this one has had some changes, I will let you set it up for 3.x. If it needs any additional attention let me know. |
Initial Commit Issue #72
@khacoder Could you give me the rights to push to your fork of the repo ? I've made the PHPCS 3.x update, but my push gets rejected. |
@khacoder Saw the invite. Thanks for that. I've just (force) pushed the updated branch. You will need to reset your local branch to the remote version to get access to the changes. As you asked to continue with the sniff yourself, I've only done a rebase and added a commit which sorts out the PHPCS 3.x compatibility and some minor updates for consistency with WPCS. Would you like me to review the logic in the |
Sure I can take a look. |
Just going over the logic and reason for this sniff. It was initially set up to replicate the more-deprecated.php sniff in the theme check plugin. The theme check is currently unchanged from when this sniff was initially developed. So why has this sniff changed? Many parameters have been added that are not deprecated, and parameters have been removed that are deprecated. So why are Error's being generated for non deprecated parameters? I would think that they should be Warnings ? Edit: Many of the alts are output by the functions, so I was kind of wondering why they are even in the sniff? |
Hey @jrfnl I think I'll let you finish this off, sorry about the above comments. Just a heads up, the error message needs some love. Also check the bloginfo() alts as bloginfo echos get bloginfo(). |
As @khacoder prompted me to look closer at the PR I realised I had worked on a sniff to check for deprecated parameter values that should be merged into WPCS itself. grappler/WordPress-Coding-Standards@61897bf For that reason I think this PR should be marked as wait for upstream for the moment till that sniff it added to WPCS and then this Sniff could extend that. |
@grappler 👍 Sounds good to me. Go for it! (and let me know if you want me to take a look in advance) |
@grappler Having just reviewed the upstream sniff, if you want to be able to extend that one, it will need some changes in the setup. |
The team decided that this should mirror Theme Check and only catch the stylesheet and directory URLs. @khacoder can fill in the details if necessary. Meeting: https://wordpress.slack.com/archives/C02RP4Y3K/p1528822802001090 |
Initial PR
Issue #72