Describe the bug
Squiz.PHP.DisallowComparisonAssignment.AssignedComparison
yields a false positive on the following code:
$this->s_dirname = (
isset($path_parts['dirname']) ? $path_parts['dirname'] : ''
);
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
LINE 183: ERROR The value of a comparison must not be assigned to a variable (Squiz.PHP.DisallowComparisonAssignment.AssignedComparison)
-----------------------------------------------------------------------------------------------------------------------------------------
181: ······$this->s_filepath·=·$s_filepath;
182: ······$path_parts·=·pathinfo($this->s_filepath);
>> 183: ······$this->s_dirname·=·(
184: ········isset($path_parts['dirname'])·?·$path_parts['dirname']·:·''
185: ······);
-----------------------------------------------------------------------------------------------------------------------------------------
Code sample
<?php
$arr = [];
$s = isset($arr['a']) ? $arr['a'] : 'b';
Custom ruleset
Not needed
To reproduce
Steps to reproduce the behavior:
- Create a file called
test.php with the code sample above...
- Run phpcs --report=code --standard=SQUIZ test.php`
- See error message displayed
FILE: /home/laurent/test.php
------------------------------------------------------------------------------------------------------------
FOUND 5 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------
LINE 1: ERROR [ ] Missing file doc comment
------------------------------------------------------------------------------------------------------------
>> 1: <?php
2:
3: $arr·=·[];
------------------------------------------------------------------------------------------------------------
LINE 4: ERROR [x] Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
LINE 4: ERROR [ ] The value of a comparison must not be assigned to a variable
LINE 4: ERROR [ ] Inline IF statements are not allowed
LINE 4: ERROR [ ] Implicit true comparisons prohibited; use === TRUE instead
------------------------------------------------------------------------------------------------------------
2:
3: $arr·=·[];
>> 4: $s·=·isset($arr['a'])·?·$arr['a']·:·'b';
------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------
Time: 37ms; Memory: 8MB
Expected behavior
No error "The value of a comparison must not be assigned to a variable".
Versions (please complete the following information)
|
|
| Operating System |
Ubuntu 26.04 |
| PHP version |
8.5.4 |
| PHP_CodeSniffer version |
4.0.4 |
| Standard |
Squiz |
| Install type |
Composer global |
Additional context
Please confirm
Describe the bug
Squiz.PHP.DisallowComparisonAssignment.AssignedComparisonyields a false positive on the following code:
Code sample
Custom ruleset
Not needed
To reproduce
Steps to reproduce the behavior:
test.phpwith the code sample above...Expected behavior
No error "The value of a comparison must not be assigned to a variable".
Versions (please complete the following information)
Additional context
Please confirm
4.xbranch of PHP_CodeSniffer.