Hi,
I tried running recent phpcs on my code base using --standard=PSR12 and
among the obvious errors there was a less obvious one: "Blank line found at
end of control structure".
This was pointing to the blank lines in if / else / elseif structures:
if ($foo) {
doFoo();
} elseif ($bar) {
doBar();
} else {
doSomethingElse();
}
I checked the text of the proposed standard and it states in section 5:
- The closing brace MUST be on the next line after the body
So I have two questions
- Is phpcs correct in interpreting the standard? Should the brace before
the elseif or else branch be considered "closing"?
- If it is correct, doesn't the rule go somewhat against the goal of
making the code more readable?
I mean, removing the blank lines yields
if ($foo) {
doFoo();
} elseif ($bar) {
doBar();
} else {
doSomethingElse();
}
The above code can also be rewritten as switch where the standard
generously allows blank lines between case statements
switch (true) {
case $foo:
doFoo();
break;
case $bar:
doBar();
break;
default:
doSomethingElse()
}
but IMO this is also harder to understand.
--
You received this message because you are subscribed to the Google Groups "PHP
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/php-fig/5a7b2e01-36d2-4ad5-b2b2-1db11f4777ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.