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
[x] I have searched the issue list and am not opening a duplicate issue.
[x] I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
[x] I have verified the issue still exists in the master branch of PHP_CodeSniffer.
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.