Skip to content

Squiz.PHP.DisallowMultipleAssignments false positive in while loop conditions #2121

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

Conversation

jrfnl
Copy link
Contributor

@jrfnl jrfnl commented Aug 15, 2018

A variable assignment in the condition of a while loop may well be enclosed in additional parenthesis to prevent issues with operator precedence when comparing the assigned value within the same condition.

Example:

while ( ( $csvdata = fgetcsv( $handle, 2000, $separator ) ) !== false ) {}

Previously only the lowest level parenthesis_owner would be examined to determine whether or not to report this as an error. Now, for while loops only, the parenthesis owners of all nested parenthesis will be examined.

Examining them early on in the sniff as the rest of the logic is superfluous if the assignment should be ignored anyway.

Includes unit test.

…onditions

A variable assignment in the condition of a `while` loop may well be enclosed in additional parenthesis to prevent issues with operator precedence when comparing the assigned value within the same condition.

Example:
```php
while ( ( $csvdata = fgetcsv( $handle, 2000, $separator ) ) !== false ) {}
```

Previously only the lowest level `parenthesis_owner` would be examined to determine whether or not to report this as an error. Now, for `while` loops only, the parenthesis owners of all nested parenthesis will be examined.

Examining them early on in the sniff as the rest of the logic is superfluous if the assignment should be ignored anyway.

Includes unit test.
@gsherwood gsherwood changed the title Squiz/DisallowMultipleAssignments: fix false positive in while loop conditions Squiz.PHP.DisallowMultipleAssignments false positive in while loop conditions Aug 16, 2018
@gsherwood gsherwood added this to the 3.3.2 milestone Aug 16, 2018
@gsherwood gsherwood merged commit e0c1c1a into squizlabs:master Aug 16, 2018
gsherwood added a commit that referenced this pull request Aug 16, 2018
@gsherwood
Copy link
Member

Thanks!

@jrfnl jrfnl deleted the feature/squiz-disallowmultipleassignments-bugfix branch August 16, 2018 03:18
@jrfnl
Copy link
Contributor Author

jrfnl commented Aug 16, 2018

You're welcome ;-)

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.

2 participants