coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

False Positive and OOM with SlevomatCodingStandard.ControlStructures.DisallowYodaComparison

Open scribblemaniac opened this issue 1 year ago • 0 comments

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

scribblemaniac avatar Jun 10 '24 00:06 scribblemaniac