False positive and false fix for `DisallowYodaComparison` via `<?=` echo short tag
herndlm opened this issue · comments
Martin Herndl commented
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) ?>">
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.
Jaroslav Hanslík commented
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.