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

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

Conversation

@jrfnl
Copy link
Contributor

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.

Squiz/DisallowMultipleAssignments: fix false positive in while loop c…
…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 the Bug label Aug 16, 2018

@gsherwood gsherwood added this to Backlog in PHPCS v3 Development via automation 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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

PHPCS v3 Development automation moved this from Backlog to Ready for Release Aug 16, 2018

gsherwood added a commit that referenced this pull request Aug 16, 2018
@gsherwood

This comment has been minimized.

Copy link
Member

commented Aug 16, 2018

Thanks!

@jrfnl jrfnl deleted the jrfnl:feature/squiz-disallowmultipleassignments-bugfix branch Aug 16, 2018

@jrfnl

This comment has been minimized.

Copy link
Contributor Author

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
2 participants
You can’t perform that action at this time.