slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False positive and false fix for `DisallowYodaComparison` via `<?=` echo short tag

herndlm opened this issue · comments

The following PHP HTML template code causes a false positive via DisallowYodaComparison:

<input
    type="radio"
    <?= $disabledInputs ? 'disabled' : '' ?>
    <?= $policy === Policy::PUBLIC->value ? 'checked' : '' ?>
    value="<?= esc_attr(Policy::PUBLIC->value) ?>">

image

even more interesting though maybe, if I try to auto-fix this I end up with the following which is syntactically very different:

<input
    type="radio"
    <?= $disabledInputs ? 'disabled' : Policy::PUBLIC->value === '' ?>
    <?= $policy ? 'checked' : '' ?>
    value="<?= esc_attr(Policy::PUBLIC->value) ?>">

it looks like the 2 independent ternaries are somehow influencing each other.
adding a semicolon after the first ternary or not using the <?= short tag but use echo() instead seems to work around it.

Our sniffs are not tested for PHP templates. I'm ok to merge PR that will fix it but we will not try to fix it ourself.