You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Generic.ControlStructures.DisallowYodaConditions sniff has a method called isArrayStatic() that determines what the sniff considers to be static arrays. When static arrays are found on the side of a condition, the sniff triggers an error. I would expect the examples below to be considered static arrays and to trigger an error, but they are not.
Code sample
[1, 2] === $value;
[null] === $value;
To reproduce
Steps to reproduce the behavior:
Create a file called test.php with the code sample above.
Run phpcs --standard=Generic --sniffs=Generic.ControlStructures.DisallowYodaConditions tests.php
Confirm that no errors were displayed.
Expected behavior
I would expect the sniff to generate a Generic.ControlStructures.DisallowYodaConditions.Found error for each line in the code sample above. Similar to what happens, for example, with ['some string'] === $value.
Versions (please complete the following information)
Operating System
Ubuntu 23.10
PHP version
8.3.4
PHP_CodeSniffer version
master
Standard
generic
Install type
git clone
Please confirm
I have searched the issue list and am not opening a duplicate issue.
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.
The text was updated successfully, but these errors were encountered:
I have removed the Status: triage label as Juliette already confirmed this to be a valid issue in squizlabs/PHP_CodeSniffer#2830 (comment). I also added the Standard: Generic label.
Describe the bug
The Generic.ControlStructures.DisallowYodaConditions sniff has a method called
isArrayStatic()
that determines what the sniff considers to be static arrays. When static arrays are found on the side of a condition, the sniff triggers an error. I would expect the examples below to be considered static arrays and to trigger an error, but they are not.Code sample
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above.phpcs --standard=Generic --sniffs=Generic.ControlStructures.DisallowYodaConditions tests.php
Expected behavior
I would expect the sniff to generate a
Generic.ControlStructures.DisallowYodaConditions.Found
error for each line in the code sample above. Similar to what happens, for example, with['some string'] === $value
.Versions (please complete the following information)
Please confirm
master
branch of PHP_CodeSniffer.The text was updated successfully, but these errors were encountered: