-
-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Description
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 (
PreserveOneLineStatementsmust not be enabled) - Blank lines after "header blocks" (
SpaceDeclarationsandSortImportsmandatory):-
<?php - file-level docblock (blank line only applied before
namespacecurrently) -
declarestatements -
namespacedeclaration - class
usestatements - function
usestatements - constant
usestatements
-
- Allow breaking over multiple lines if every item is on its own line (
NoMixedListsmandatory):-
implementsandextendsinterfaces- Trigger if a newline appears after
implementsorextends, not just between first two interfaces - Add a newline before the opening brace of an anonymous
classwith an interface list that wraps
- Trigger if a newline appears after
- Parameters in
functiondeclarations - Variables in anonymous function
usedeclarations - Arguments in
functioncalls - Statements in
forloops
-
- One-line
declareat 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
trollfalgar and The-Paavo