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 false fix for DisallowYodaComparison via <?= echo short tag #1658

Open
herndlm opened this issue Jan 29, 2024 · 1 comment

Comments

@herndlm
Copy link
Contributor

herndlm commented Jan 29, 2024

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.

@herndlm herndlm changed the title False positive and false fix for DisallowYodaComparison False positive and false fix for DisallowYodaComparison via <?= echo short tag Jan 29, 2024
@kukulich
Copy link
Contributor

kukulich commented Mar 9, 2024

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.

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

2 participants