-
-
Notifications
You must be signed in to change notification settings - Fork 89
Closed
Labels
Milestone
Description
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
<?php
$filtered_results[ $i ]->$field = $result;
Custom ruleset
Can be reproduced with the WordPress-Extra
or Squiz
rulesets, or any combination using the Squiz.PHP.DisallowMultipleAssignments
rule.
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php
with the code sample above... - Run
phpcs test.php --standard=Squiz --sniffs=Squiz.PHP.DisallowMultipleAssignments -s
or similar - See error message displayed
3 | ERROR | Assignments must be the first block of code on a line (Squiz.PHP.DisallowMultipleAssignments.Found)
Expected behavior
No violation reported.
Versions (please complete the following information)
Operating System | MacOS 14.6.1 |
PHP version | 7.4 |
PHP_CodeSniffer version | 3.9.2 |
Standard | Squiz |
Install type | Composer |
Additional context
None of the tests seem to have an assignment to a property of an object in an array.
Please confirm
- I have searched the issue list and am not opening a duplicate issue.
- I have read the Contribution Guidelines and this is not a support question.
- I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
- I have verified the issue still exists in the
master
branch of PHP_CodeSniffer.