Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic/DisallowYogaConditions: false negatives when handling arrays #467

Open
3 tasks done
rodrigoprimo opened this issue Apr 26, 2024 · 1 comment
Open
3 tasks done

Comments

@rodrigoprimo
Copy link
Contributor

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

[1, 2] === $value;
[null] === $value;

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above.
  2. Run phpcs --standard=Generic --sniffs=Generic.ControlStructures.DisallowYodaConditions tests.php
  3. 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.
@rodrigoprimo
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant