Configuration reference

The formatter is opinionated and ships sensible PER-CS defaults, but a handful of options let you tune it to a different house style. Everything sits under the [formatter] table.

[formatter]
print-width = 100
use-tabs = true

Presets

A preset is a complete bundle of formatter options tuned for a specific coding standard.

[formatter]
preset = "laravel"
PresetWhat it is
defaultPER-CS compliant. Same as the built-in defaults.
psr-12PSR-12 coding standard.
laravelLaravel Pint's laravel preset.
drupalDrupal coding standard.

Presets accept a version suffix:

preset = "psr-12@latest"
preset = "psr-12"          # same as @latest

Today only latest is supported. Future Mago releases will allow pinning to specific standard versions.

You can also combine a preset with individual options. The preset provides the base; explicit options override it.

[formatter]
preset = "laravel"
print-width = 140

Tool-wide options

OptionTypeDefaultDescription
presetstringnoneOne of default, psr-12, laravel, drupal.
excludesstring list[]Paths or globs the formatter skips. Additive to source.excludes.

excludes here adds to the global list. Files matched globally are always excluded; this option lets you exclude additional files from the formatter only.

[source]
excludes = ["cache/**"]                          # excluded from every tool

[formatter]
excludes = ["src/**/AutoGenerated/**/*.php"]     # additionally excluded from formatting

Layout and width

OptionTypeDefaultDescription
print-widthinteger120Maximum line length the printer wraps at.
tab-widthinteger4Spaces per indentation level.
use-tabsbooleanfalseUse tabs instead of spaces.
end-of-lineenum"lf"Line terminator. Values: auto, lf, crlf, cr.
single-quotebooleantruePrefer single quotes for strings.
indent-heredocbooleantrueIndent heredoc/nowdoc body to match the surrounding scope (PER-CS 3.0 §10). When false, body and closing label sit at column 0.
trailing-commabooleantrueAdd a trailing comma to multi-line arrays, parameter lists, etc.
remove-trailing-close-tagbooleantrueStrip the trailing ?> from files.

Brace placement

OptionTypeDefaultDescription
control-brace-styleenum"same-line"Braces for control structures.
following-clause-on-newlinebooleanfalsePut else, elseif, catch, finally on a new line.
closure-brace-styleenum"same-line"Braces for closures and anonymous classes.
function-brace-styleenum"next-line"Braces for functions.
method-brace-styleenum"next-line"Braces for methods.
classlike-brace-styleenum"always-next-line"Braces for classes, traits, interfaces, enums.

The brace-style enums all accept the same three values:

  • same-line: opening brace stays on the declaration line.
  • next-line: opening brace goes on the next line for single-line signatures, but stays on the declaration line when the signature breaks across lines.
  • always-next-line: opening brace always goes on the next line, even when the signature breaks.

For method-brace-style = "next-line":

public function foo(): string
{
}

public function bar(
    string $veryLongParam,
): string {
}

For method-brace-style = "always-next-line":

public function bar(
    string $veryLongParam,
): string
{
}

Empty bodies

OptionTypeDefaultDescription
inline-empty-control-bracesbooleanfalseInline empty control-structure bodies.
inline-empty-closure-bracesbooleantrueInline empty closure bodies.
inline-empty-function-bracesbooleantrueInline empty function bodies.
inline-empty-method-bracesbooleantrueInline empty method bodies.
inline-empty-constructor-bracesbooleantrueInline empty constructor bodies.
inline-empty-classlike-bracesbooleantrueInline empty class-like bodies.
inline-empty-anonymous-class-bracesbooleantrueInline empty anonymous-class bodies.

Method chains

OptionTypeDefaultDescription
method-chain-breaking-styleenum"next-line"Once a chain breaks, where the call sits. Values: same-line, next-line.
first-method-chain-on-new-linebooleantrueWhen an object chain (->, ?->) breaks, put the first call on a new line. Static access (::) stays attached to its target (PER-CS 4.7).
method-chain-semicolon-on-next-linebooleanfalseWhen a multi-line chain is a statement, put the terminating semicolon on its own line.
preserve-breaking-member-access-chainbooleanfalsePreserve existing line breaks in member-access chains.
preserve-breaking-member-access-chain-first-method-on-same-linebooleanfalseWhen preserving a broken chain, keep the first method on the receiver line.

Preserving author breaks

OptionTypeDefaultDescription
preserve-breaking-argument-listbooleanfalsePreserve existing line breaks in argument lists.
preserve-breaking-array-likebooleantruePreserve existing line breaks in array-likes.
preserve-breaking-parameter-listbooleanfalsePreserve existing line breaks in parameter lists.
preserve-breaking-attribute-listbooleanfalsePreserve existing line breaks in attribute lists.
preserve-breaking-conditional-expressionbooleanfalsePreserve existing line breaks in ternaries.
preserve-breaking-condition-expressionbooleanfalsePreserve existing line breaks in control-structure conditions. When enabled, each boolean operator goes on its own line.
break-promoted-properties-listbooleantrueAlways break parameter lists with promoted properties.
parameter-attribute-on-new-linebooleantruePut parameter attributes on their own line when the parameter list breaks (PER-CS 12.2).
line-before-binary-operatorbooleantrueWhen a binary expression breaks, place the operator on the next line.
indent-binary-expression-continuationbooleanfalseIndent continuation lines of binary expressions in assignments. Available since 1.19.
omit-redundant-arithmetic-binary-expression-parenthesesbooleanfalseDrop redundant parens around arithmetic when comparison or null coalesce already preserves meaning.
omit-redundant-bitwise-binary-expression-parenthesesbooleanfalseDrop redundant parens around bitwise sub-expressions when precedence already preserves meaning.
preserve-redundant-logical-binary-expression-parenthesesbooleanfalseKeep author-written parens around a logical sub-expression when its parent is also logical.

Argument and parameter alignment

OptionTypeDefaultDescription
always-break-named-arguments-listbooleanfalseAlways break named-argument lists.
always-break-attribute-named-argument-listsbooleanfalseAlways break named arguments in attributes.
align-parametersbooleanfalseColumn-align multi-line parameter lists by the variable.
align-named-argumentsbooleanfalseColumn-align named arguments in multi-line calls and attributes.
array-table-style-alignmentbooleantrueUse table-style alignment for arrays.
align-assignment-likebooleanfalseColumn-align consecutive assignment-like constructs (variables, multi-line array key/value pairs, properties, constants, enum cases, match arms). Compact inline arrays stay unaligned.

use statements

OptionTypeDefaultDescription
sort-usesbooleantrueSort use statements alphabetically.
sort-class-methodsbooleanfalseOrder class methods by visibility and type: constructor first, then static methods, then instance methods by visibility, destructor last.
separate-use-typesbooleantrueInsert a blank line between different kinds of use.
expand-use-groupsbooleantrueExpand grouped use statements into individual ones.

Type hints and constructs

OptionTypeDefaultDescription
null-type-hintenum"question"How to format nullable types. null_pipe rewrites ?T to null|T, preserving union order. null_pipe_last rewrites ?T to T|null and reorders unions to put null last. question rewrites null|T and T|null to ?T.
parentheses-around-new-in-member-accessbooleanfalseWrap new in member access: (new Foo)->bar().
parentheses-in-new-expressionbooleantrueAdd () to new without arguments: new Foo().
parentheses-in-exit-and-diebooleantrueAdd () to exit and die.
parentheses-in-attributebooleanfalseAdd () to attributes without arguments.

Whitespace around operators

OptionTypeDefaultDescription
space-before-arrow-function-parameter-list-parenthesisbooleanfalseSpace before arrow function parameter list.
space-before-closure-parameter-list-parenthesisbooleantrueSpace before closure parameter list.
space-before-hook-parameter-list-parenthesisbooleanfalseSpace before property-hook parameter list.
inline-abstract-property-hooksbooleantrueKeep abstract property hooks (get;, set;) on one line (PER-CS 4.10).
space-before-closure-use-clause-parenthesisbooleantrueSpace before closure use (...).
space-after-cast-unary-prefix-operatorsbooleantrueSpace after cast operators like (int).
space-after-reference-unary-prefix-operatorbooleanfalseSpace after &.
space-after-error-control-unary-prefix-operatorbooleanfalseSpace after @.
space-after-logical-not-unary-prefix-operatorbooleanfalseSpace after !.
space-after-bitwise-not-unary-prefix-operatorbooleanfalseSpace after ~.
space-after-increment-unary-prefix-operatorbooleanfalseSpace after prefix ++.
space-after-decrement-unary-prefix-operatorbooleanfalseSpace after prefix --.
space-after-additive-unary-prefix-operatorbooleanfalseSpace after unary + and -.
space-around-concatenation-binary-operatorbooleantrueSpaces around ..
space-around-assignment-in-declarebooleanfalseSpaces around = in declare.
space-within-grouping-parenthesisbooleanfalseSpaces inside grouping parens: ( 1 + 2 ).

Blank lines

OptionTypeDefaultDescription
empty-line-after-control-structurebooleanfalseBlank line after a control structure.
opening-tag-on-own-linebooleantruePut <?php on its own line in pure PHP files (PER-CS 3.0). Templates with inline HTML are unaffected.
empty-line-after-opening-tagbooleantrueBlank line after <?php.
empty-line-after-declarebooleantrueBlank line after declare.
empty-line-after-namespacebooleantrueBlank line after namespace.
empty-line-after-usebooleantrueBlank line after use blocks.
empty-line-after-symbolsbooleantrueBlank line after top-level symbols.
empty-line-between-same-symbolsbooleantrueBlank line between consecutive symbols of the same type. Only applies when empty-line-after-symbols is true.
empty-line-after-class-like-openbooleanfalseBlank line after the opening brace of a class-like.
empty-line-after-class-like-constantbooleanfalseBlank line after a class constant.
empty-line-before-class-like-closebooleanfalseBlank line before the closing brace of a non-empty class-like.
empty-line-after-enum-casebooleanfalseBlank line after an enum case.
empty-line-after-trait-usebooleanfalseBlank line after a trait use.
empty-line-after-propertybooleanfalseBlank line after a property.
empty-line-after-methodbooleantrueBlank line after a method.
empty-line-before-returnbooleanfalseBlank line before a return.
empty-line-before-dangling-commentsbooleantrueBlank line before dangling comments.
separate-class-like-membersbooleantrueBlank line between different kinds of class member.

Casing

OptionTypeDefaultDescription
uppercase-literal-keywordbooleanfalseWhen true, format true, false, null in UPPERCASE.

↳ Edit this page →