Hey guys,
I'm using phpcs with the PSR-2 ruleset, but I'm getting several new/empty lines errors.
I'd like to understand if it's me misreading the standard or phpcs being over-zealous :)
1. Empty lines and switch/caseWe often use empty lines to improve the readability of switch/cases, like:
switch ($var) {
case 1:
return $something;
case 2:
return $somethingElse;
}
but phpcs doesn't like it:
Blank lines are not allowed between case statements; found 1
What rules is this based on? The switch/case section doesn't talk about empty lines at all
A switch
structure looks like the following. Note the placement of
parentheses, spaces, and braces. The case
statement MUST be indented once
from switch
, and the break
keyword (or other terminating keyword) MUST be
indented at the same level as the case
body. There MUST be a comment such as
// no break
when fall-through is intentional in a non-empty case
body.
2. Empty lines and method callsWe also use empty lines to improve readability of multi-line method calls (particularly when setting up mocks, because some method calls have a logical grouping), like:
$this
->a()
->b()
->c()
->d()
but again phpcs complains:
Empty lines are not allowed in multi-line function calls
In this case the rule says
When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis, there MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis. In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma.
Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.
but it doesn't anything about empty lines (and I don't think empty lines count as trailing white space, right?)
3. New lines and semicolonsWhen concatenating several calls we usually put the semicolon on a new line, which is useful to re-order/add calls (similar to trailing semicolons in arrays), like this:
$this
->a()
->b()
->c()
;
However, this generates the following error:
Space after closing parenthesis of function call prohibited
and I'm unsure what rule is this coming from.
Thanks
Giacomo