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

False Positive and OOM with SlevomatCodingStandard.ControlStructures.DisallowYodaComparison #1687

Open
scribblemaniac opened this issue Jun 10, 2024 · 0 comments

Comments

@scribblemaniac
Copy link

Consider the following small example php file:

<?= $a == 1 ? 'Yes' : 'No' ?>
<?= $b == STATUS ? 'Yes' : 'No' ?>

When running phpcs --standard=SlevomatCodingStandard --sniffs=SlevomatCodingStandard.ControlStructures.DisallowYodaComparison on this file, it results in an out-of-memory exception. Increasing the memory limit well beyond what should be necessary (ex. 1GB) does not help. However if an empty set of php tags is added like so:

<?php ?>
<?= $a == 1 ? 'Yes' : 'No' ?>
<?= $b == STATUS ? 'Yes' : 'No' ?>

It can now run without an out-of-memory error. However, now it reports a false positive on line 3. Attempting to fix this error automatically with phpcbf results in this code which is definitely not equivalent:

<?php ?>
<?= $a == 1 ? 'Yes' : STATUS == 'No' ?>
<?= $b ? 'Yes' : 'No' ?>

Slevomat version: 8.15.0
PHP Version: 7.4.33

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

No branches or pull requests

1 participant