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

PSR12/OperatorSpacing: hot fix #2697

Merged

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Nov 14, 2019

PR #2640 made it so the Squiz.WhiteSpace.OperatorSpacing sniff now sets a property with the $nonOperandTokens from the register() method.

However, the PSR12 sniff for the same extends the Squiz sniff, but overloads the register() method to set different targets.

This means that the $nonOperandTokens array was empty and therefore the isOperator() method would nearly always return true, which was often incorrect.

Fixed by calling the parent::register() method before setting the $targets for the PSR12 sniff.

Includes adding unit tests to the PSR12 sniff related to the exclusions handled via the isOperator() method, to prevent breakage like this from being able to be merged in the future.

Fixes #2696

PR squizlabs#2640 made it so the `Squiz.WhiteSpace.OperatorSpacing` sniff now sets a property with the `$nonOperandTokens` from the `register()` method.

However, the PSR12 sniff for the same extends the Squiz sniff, but overloads the `register()` method to set different targets.

This means that the `$nonOperandTokens` array was empty and therefore the `isOperator()` method would nearly always return `true`, which was often incorrect.

Fixed by calling the `parent::register()` method before setting the `$targets` for the PSR12 sniff.

Includes adding unit tests to the PSR12 sniff related to the exclusions handled via the `isOperator()` method, to prevent breakage like this from being able to be merged in the future.
gsherwood added a commit that referenced this pull request Nov 14, 2019
@gsherwood gsherwood merged commit 28c49d1 into squizlabs:master Nov 14, 2019
@gsherwood
Copy link
Member

Thanks so much for finding and fixing this before it was released.

@jrfnl
Copy link
Contributor Author

jrfnl commented Nov 15, 2019

Thanks so much for finding and fixing this before it was released.

A failing external standards build kind of helps with that ;-)

@jrfnl jrfnl deleted the feature/2696-psr12-operatorspacing-bugfix branch November 15, 2019 04:14
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.

PSR12.Operators.OperatorSpacing: false positives
2 participants