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

Sniff::get_function_call_parameters(): correctly handle closures when passed as param #1387

Merged
merged 1 commit into from
Jun 26, 2018

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 25, 2018

Closures can be declared within function calls when the function expects a call-back.
This situation was only partially handled within the Sniff::get_function_call_parameters() method.

Most of the time when a comma is encountered within a closure, it will be at a different nesting level than the original function call/array, which meant it would be disregarded and the method would return the correct results.
However, there are some, albeit rare, situations in which the comma would be at the target nesting level, causing the method to split the closure into two or more "parameters".

As far as I know, this bug has not caused any issues for any of the WPCS sniffs so far, but the situation should be handled correctly even so.

I came across this while working on #1371, the PR for which will contain a unit test covering this fix.

Additionally, the same fix has been pulled to the PHPCompatibility standard with dedicated unit tests.
See: PHPCompatibility/PHPCompatibility#682

Related to #764

@jrfnl jrfnl added this to the 1.0.0 milestone Jun 25, 2018
@jrfnl jrfnl force-pushed the feature/fix-function-call-params-method branch from 83e1666 to cfc54c5 Compare June 25, 2018 20:39
… passed as param

Closures can be declared within function calls when the function expects a call-back.
This situation was only partially handled within the `Sniff::get_function_call_parameters()` method.

Most of the time when a comma is encountered within a closure, it will be at a different nesting level than the original function call/array, which meant it would be disregarded and the method would return the correct results.
However, there are some, albeit rare, situations in which the comma would be at the target nesting level, causing the method to split the closure into two or more "parameters".

As far as I know, this bug has not caused any issues for any of the WPCS sniffs so far, but the situation should be handled correctly even so.

I came across this while working on 1371, the PR for which will contain a unit test covering this fix.

Additionally, the same fix has been pulled to the PHPCompatibility standard with dedicated unit tests.
See: PHPCompatibility/682

Related to 764
@jrfnl jrfnl mentioned this pull request Jun 25, 2018
10 tasks
@GaryJones
Copy link
Member

Any unit tests needed for this?

@jrfnl
Copy link
Member Author

jrfnl commented Jun 26, 2018

@GaryJones

I came across this while working on #1371, the PR for which will contain a unit test covering this fix.

Additionally, the same fix has been pulled to the PHPCompatibility standard with dedicated unit tests.
See: PHPCompatibility/PHPCompatibility#682

While the unit tests in PHPCompatibility are of course in a different repo, the function used is the same in both (as I wrote & pulled it) and PHPCompatibility is better set up to unit test utility methods, while WPCS is not.

The unit test in the PregQuote sniff will cover the change sufficiently for WPCS once it is pulled.

@JDGrimes JDGrimes merged commit f557fe5 into develop Jun 26, 2018
@JDGrimes JDGrimes deleted the feature/fix-function-call-params-method branch June 26, 2018 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants