Open GaryJones opened 4 weeks ago
@GaryJones Thanks for reporting this. I can confirm the issue, which appears to be caused by the variable variable, i.e. the variable for the property name:
$filtered_results[] = $result;
$filtered_results[ $i ] = $result;
$filtered_results->field = $result;
$filtered_results->$field = $result;
$filtered_results[ $i ]->field = $result;
$filtered_results[ $i ]->$field = $result; // <- This is the bug, all other test cases in this code sample are handled correctly.
@GaryJones PR #610 should fix this. Testing appreciated.
Describe the bug
False positive on a complex statement that suggests the assignment is not the first block of code.
Try assigning a value to a property of an object contained in an (indexed) array.
Code sample
Custom ruleset
Can be reproduced with the
WordPress-Extra
orSquiz
rulesets, or any combination using theSquiz.PHP.DisallowMultipleAssignments
rule.To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php --standard=Squiz --sniffs=Squiz.PHP.DisallowMultipleAssignments -s
or similarExpected behavior
No violation reported.
Versions (please complete the following information)
Additional context
None of the tests seem to have an assignment to a property of an object in an array.
Please confirm
master
branch of PHP_CodeSniffer.