Plugin-php: Better output `extends` and `implements`

Created on 6 Mar 2018  路  5Comments  路  Source: prettier/plugin-php

From PSR-12: https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-style-guide.md#41-extends-and-implements

class ClassName extends ParentClass implements
    \ArrayAccess,
    \Countable,
    \Serializable
{
    // constants, properties, methods
}

vs

class ClassName 
    extends ParentClass 
    implements \ArrayAccess, \Countable, \Serializable
{
    // constants, properties, methods
}

In php __ONLY__ one class maybe extends. Vote welcome.

  • :+1: - First example
  • :heart: - Second example
psr compat

Most helpful comment

Sounds good! That would probably mean that the "worst case" looks like this, right?

class ClassNameLoooooooooooooooooooooooooooooooooong
    extends ParentClassLoooooooooooooooooooooooooooooooooong
    implements 
        \ArrayAccessLooooooooooooooooooong, 
        \CountableLooooooooooooooooooong, 
        \SerializableLooooooooooooooooooong
{
    // constants, properties, methods
}

All 5 comments

Lists of implements and extends 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 interface per line.

Funny that PSR-12 speaks of "lists of extends" when there can be only one. I'd opt for the first style as because both styles look fine but the first seems to be preferred by PSR-12.

Should we consider preferring option 1 but breaking to option 2 if we hit the line length limit?

Sounds good! That would probably mean that the "worst case" looks like this, right?

class ClassNameLoooooooooooooooooooooooooooooooooong
    extends ParentClassLoooooooooooooooooooooooooooooooooong
    implements 
        \ArrayAccessLooooooooooooooooooong, 
        \CountableLooooooooooooooooooong, 
        \SerializableLooooooooooooooooooong
{
    // constants, properties, methods
}

@mgrip @czosel how about open issue for https://github.com/php-fig/fig-standards about this. I am confused about this. Because extends class may have very long value and PSR-12 output is ugly

@mgrip also i agree maybe better by default 1. If line over limit use 2 :+1:

Not fixed fully

Was this page helpful?
0 / 5 - 0 ratings

Related issues

czosel picture czosel  路  5Comments

Epskampie picture Epskampie  路  4Comments

aboyton picture aboyton  路  4Comments

alexander-akait picture alexander-akait  路  3Comments

czosel picture czosel  路  5Comments