Skip to content

Add support for formatting-related requirements of PSR-12 #4

@lkrms

Description

@lkrms

PrettyPHP's default formatting is largely PSR-12 compliant, but there are some differences to address.

Parts of PSR-12, e.g. PascalCase class names, fall outside the scope of a formatter and won't be implemented, although exceptions are sometimes made (use import statements are already sorted by default, for example).

  • LF line endings
  • Indent of 4 spaces
  • Line length "SHOULD NOT" exceed 80 characters and "MUST" have a soft limit of 120 characters
  • One statement per line (PreserveOneLineStatements must not be enabled)
  • Blank lines after "header blocks" (SpaceDeclarations and SortImports mandatory):
    • <?php
    • file-level docblock (blank line only applied before namespace currently)
    • declare statements
    • namespace declaration
    • class use statements
    • function use statements
    • constant use statements
  • Allow breaking over multiple lines if every item is on its own line (NoMixedLists mandatory):
    • implements and extends interfaces
      • Trigger if a newline appears after implements or extends, not just between first two interfaces
      • Add a newline before the opening brace of an anonymous class with an interface list that wraps
    • Parameters in function declarations
    • Variables in anonymous function use declarations
    • Arguments in function calls
    • Statements in for loops
  • One-line declare at line 1 of files also containing markup: <?php declare(strict_types=1) ?>
    • Suppress newline before close tag even if present in source
  • Force newlines before and after control structure expressions split over multiple lines
  • Add whitespace between exception types in catch
  • Enforce newline before first method in multiline method chains

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions