AssignmentInCondition: also check ternary conditions + warning for non variable assignment #1100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the original PR, the conditions for ternaries were explicitly not examined by this sniff.
This PR changes that. As long as either the condition, i.e. the part before the
?
is within parentheses, òr the complete ternary is within parentheses, they will now be examined and throw the appropriate errors.I suspect this may still be a little buggy with parentheses not belonging to the ternary, but with a ternary somewhere within them allowing this sniff to trigger.
More unit test cases very welcome!
For now, I'm only pulling this in WPCS. Once the worst bugs have been removed, I will upstream this improvement to the PHPCS version as well.
This PR also enables warnings to be thrown for non-variable assignments as those are even more likely to be typos:
if ( CONSTANT = 3 ){}