-
Hi, quick question / potentially longer discussion ;) This is about a potential sniff PSR-12 inconsistency with alternative syntax for control structures. PSR-12 states (under 5. Control Structures)
And apparently <?php if ($foo)): ?>
<?= esc_html($foo) ?>
<?php endif; ?> with
So it wants that space after the closing paranthesis and before the colon: <?php if ($foo)) : ?>
<?= esc_html($foo) ?>
<?php endif; ?> But I was wondering - is that really on purpose or a potential bug? At least PSR-12 seems to be not specifing that as it deals only with spaces before the opening brace, right? Btw. unrelated: thank you everyone for the hard work on phpcs! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
First, I strongly recommend not trying to enforce PSR12 on template code. Alternate syntax rules were excluded from the PSR standards on purpose so they wouldn't mix template standards with other coding standards. Hence the use of "brace" everywhere. But if you want to use it, PHPCS sees the opening brace of this alternate IF syntax as the You may also want to consider excluding this specific sniff or error code from checking your template files if you still want the rest of PSR-12 applied. You'd need a <rule ref="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis">
<exclude-pattern>*.tpl</exclude-pattern>
</rule> More info here: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset |
Beta Was this translation helpful? Give feedback.
First, I strongly recommend not trying to enforce PSR12 on template code. Alternate syntax rules were excluded from the PSR standards on purpose so they wouldn't mix template standards with other coding standards. Hence the use of "brace" everywhere.
But if you want to use it, PHPCS sees the opening brace of this alternate IF syntax as the
:
and the closing brace as theendif
. The sniffs that check control structures don't care if you're using regular or alternate syntax - they just check that the opening and closing scope tokens are in the right spots. This behaviour is completely intentional throughout PHPCS.You may also want to consider excluding this specific sniff or error code from…