[PSR-12] Blank line after trait use import statement

543 views
Skip to first unread message

Greg Sherwood

unread,
Apr 22, 2018, 7:52:02 PM4/22/18
to PHP Framework Interoperability Group
Hi,

I wrote the PSR-1 and PSR-2 standards for PHP_CodeSniffer and I'm now writing a PSR-12 standard as well. I have a question about this section:

4.2 Using traits
...
When the class has nothing after the use import statement, the class closing brace MUST be on the next line after the use import statement.
...
Otherwise it MUST have a blank line after the use import statement.

<?php

namespace Vendor\Package;

use Vendor\Package\FirstTrait;

class ClassName
{
    use FirstTrait;

    private $property;
}

The rule states that the use import statement must have a blank like after it, but should PHPCS enforce a single blank line or at least one blank line? Is this valid code?

<?php

namespace Vendor\Package;

use Vendor\Package\FirstTrait;

class ClassName
{
   
use FirstTrait;




   
private $property;
}

Thanks

Joe T.

unread,
Apr 22, 2018, 10:24:10 PM4/22/18
to PHP Framework Interoperability Group
i'm not in the WG, but i always restrict to 1 blank line between any two structures - aside from line after opening { and before closing } where no blank line is permitted. Extra blank lines feel like something wasn't finished. It's just... ew.
-jlt

Alessandro Lai

unread,
Apr 23, 2018, 2:34:17 AM4/23/18
to PHP Framework Interoperability Group
No, multiple blank lines are not allowed in the current spec. Section 3 refers to a SINGLE blank line:

"The header of a PHP file may consist of a number of different blocks. If present, each of the blocks below MUST be separated by a single blank line, and MUST NOT contain a blank line."

Greg Sherwood

unread,
Apr 23, 2018, 4:58:26 AM4/23/18
to PHP Framework Interoperability Group
The use group I'm talking about is for importing traits and not the use block in the header of the file. In the example file given in that section, these use statements fall into the area denoted by the comment "// ... additional PHP code ..." so I can't see how that section applies to these statements directly.

Larry Garfield

unread,
Apr 23, 2018, 4:41:07 PM4/23/18
to php...@googlegroups.com
I would concur here. The spec should be adapted to clarify that all blank
line rules are single-blank-line rules.

--Larry Garfield

On Sunday, April 22, 2018 9:24:10 PM CDT Joe T. wrote:
> i'm not in the WG, but i always restrict to 1 blank line between any two
> structures - aside from line after opening *{* and before closing *}* where
signature.asc
Reply all
Reply to author
Forward
0 new messages