When using the PSR2 ruleset I'm getting an error for the following:
if (
$cond1
&& $cond2
) {
...
}
Error states the following
ERROR | [x] Expected 0 spaces after opening bracket; newline found
(PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace)
When I alter the code as follows then the error disappears:
if ($cond1
&& $cond2
) {
...
}
From my understanding PSR2 does allow a newline after the opening parenthesis if the if conditions are split to multiple lines. Or am I wrong and the sniff is working as expected?
Also the sniff is a bit confusing as it says the newline is next to a bracket instead of the opening parenthesis.
I found #460 now. GitHub search is not fuzzy it seems.
So the problem would be that the fix would not play well together with the fixer tool?
So the problem would be that the fix would not play well together with the fixer tool?
The problem is that PSR-2 does not describe this as valid syntax and nobody from the PHP-FIG has ever said otherwise, or added errata about it. So the only rule to go on is:
Opening parentheses for control structures MUST NOT have a space after them, and closing parentheses for control structures MUST NOT have a space before.
Which I think is pretty clear. You can't have whitespace after the opening parenthesis, so the first condition can't start on the next line.
If you want to read the full discussion, you can do so on the issue you linked, but no additional information has ever been made available, so my position needs to stay the same: redefining "space" in PSR-2 to only mean a space character and not newlines would completely break PSR-2, so I'm not going to change PHPCS in this way.
Hopefully that explains things.
I see. Thanks for the clarification. Will probably just disable the sniff on my end to make multiline conditionals more readable (in my opinion). :)
We can take a look at this later on if PSR2 is clarified on this point.
Thanks!