Customize formatting#
Many companies have coding guidelines when creating source code. Our PHP formatter can be highly customized to follow those guidelines.
Since version 1.24
customizable formatter is available for PREMIUM users. Community version users can still influence the formatter behavior through php.format.codestyle
settings.
php.format.codestyle
setting serves as a base and each formatting option you specify will override the particular behaviour.
Note: The list of options grows each release, please let us know what option are you missing.
General#
Keep control statements on one line#
Setting: php.format.rules.keepControlStatementsOnOneLine
Control statements are kept on one line.
Enabled
Disabled
Keep functions on one line#
Coming soon...
Setting: php.format.rules.keepFunctionsOnOneLine
Functions and methods are kept on one line.
Enabled
Disabled
Keep classes on one line#
Coming soon...
Setting: php.format.rules.keepClassesOnOneLine
Clasess are kept on one line.
Enabled
Disabled
Braces#
Open brace on a new line for functions#
Setting: php.format.rules.openBraceOnNewLineForFunctions
Place open brace {
on a new line for methods, functions and constructors.
Enabled
Disabled
Open brace on a new line for lambda functions#
Setting: php.format.rules.openBraceOnNewLineForLambdas
Place open brace {
on a new line for lambda functions.
Enabled
Disabled
Open brace on a new line for anonymous classes#
Setting: php.format.rules.openBraceOnNewLineForAnonymousClasses
Place open brace {
on a new line for anonymous classes.
Enabled
Disabled
Open brace on a new line for types#
Setting: php.format.rules.openBraceOnNewLineForTypes
Place open brace {
on a new line for types.
Enabled
Disabled
Open brace on a new line for namespaces#
Setting: php.format.rules.openBraceOnNewLineForNamespaces
Place open brace {
on a new line for namespace declarations.
Enabled
Disabled
Open brace on a new line for blocks#
Setting: php.format.rules.openBraceOnNewLineForBlocks
Place open brace {
on a new line for all types of code blocks, except for those controlled by other formatting rules.
Enabled
Disabled
Indentation#
Indent braces#
Setting: php.format.rules.indentBraces
Indent curly braces ({
and }
).
Enabled
Disabled
Spacing#
Space after cast#
Setting: php.format.rules.spaceAfterCast
Insert a space after a cast operator.
Enabled
Disabled
Space after unary not !
#
Setting: php.format.rules.spaceAfterUnaryNot
Insert a space after a unary not operator.
Enabled
Disabled
Space around concatenation .
#
Setting: php.format.rules.spaceAroundConcatenation
Insert a space around concatenation operator.
Enabled
Disabled
Space before parentheses in arrow functions#
Setting: php.format.rules.spaceBeforeParenthesesInArrowFunctions
Insert a space before arrow function parentheses.
Enabled
Disabled
Space before parentheses in control statements#
Setting: php.format.rules.spaceBeforeParenthesesInControlStatements
Insert a space before parentheses in control statements.
Enabled
Disabled
Space before parentheses in function calls#
Setting: php.format.rules.spaceBeforeParenthesesInCalls
Insert a space before parentheses in method, function and constructor call parentheses.
Enabled
Disabled
Space before parentheses in declarations#
Setting: php.format.rules.spaceBeforeParenthesesInDeclarations
Insert a space before parentheses in method, function and constructor declaration parentheses.
Enabled
Disabled
Space before colon :
in control flow statements#
Setting: php.format.rules.spaceBeforeColonInControlStatements
Insert a space before colon in control flow blocks.
Enabled
Disabled
Space before colon :
in return type#
Setting: php.format.rules.spaceBeforeColonInReturnType
Insert a space before colon in a return type
Enabled
Disabled
Space within call parentheses#
Setting: php.format.rules.spaceWithinCallParens
Insert a space within method, function and constructor call parentheses.
Enabled
Disabled
Space within declaration parentheses#
Setting: php.format.rules.spaceWithinDeclParens
Insert a space within method, function and constructor declaration parentheses.
Enabled
Disabled
Space within array initializer parentheses#
Setting: php.format.rules.spaceWithinArrayInitilizersParens
Insert a space within array initializer parentheses.
Enabled
Disabled
Space within if
parentheses#
Setting: php.format.rules.spaceWithinIfParens
Insert a space within if
statement header parentheses.
Enabled
Disabled
Space within while
parentheses#
Setting: php.format.rules.spaceWithinWhileParens
Insert a space within while
statement header parentheses.
Enabled
Disabled
Space within for
parentheses#
Setting: php.format.rules.spaceWithinForParens
Insert a space within for
statement header parentheses.
Enabled
Disabled
Space within foreach
parentheses#
Setting: php.format.rules.spaceWithinForeachParens
Insert a space within foreach
statement header parentheses.
Enabled
Disabled
Space within switch
parentheses#
Setting: php.format.rules.spaceWithinSwitchParens
Insert a space within switch
statement header parentheses.
Enabled
Disabled
Space within catch
parentheses#
Setting: php.format.rules.spaceWithinCatchParens
Insert a space within catch
statement header parentheses.
Enabled
Disabled
Space within brackets []
#
Setting: php.format.rules.spaceWithinBrackets
Insert a space within brackets.
Enabled
Disabled
Space within brackets []
around expression#
Setting: php.format.rules.spaceWithinBracketsAroundExpression
Insert a space within brackets around expression.
Enabled
Disabled
Space within parentheses around expression#
Setting: php.format.rules.spaceWithinExpressionParens
Insert a space within parentheses around expression.
Enabled
Disabled
Wrapping#
Array Initilizers#
Wrap#
Setting: php.format.rules.arrayInitializersWrap
Defines wrapping behavior for array initializers.
Off
- No wrapping is appliedOn every item
- When this option is selected each item is placed on a new line and properly indented if the array initializer is split across multiple lines.
New line before first element#
Setting: php.format.rules.arrayInitializersNewLineBeforeFirstElement
Place a new line before the first array element when wrapping.
Enabled
Disabled
New line after last element#
Setting: php.format.rules.arrayInitializersNewLineAfterLastElement
Place a new line after the last element when wrapping.
Enabled
Disabled
Align key-value pairs#
Setting: php.format.rules.arrayInitializersAlignKeyValuePairs
Automatically align =>
operators.
Enabled
Disabled
Call parameters#
Wrap#
Setting: php.format.rules.callParametersWrap
Defines wrapping behavior for method, function and constructor call parameters.
Off
- No wrapping is appliedOn every item
- When this option is selected each item is placed on a new line and properly indented if the call arguments are split across multiple lines.
New line after (
#
Setting: php.format.rules.callParametersNewLineAfterLeftParen
Place a new line after the left opening parenthesis (
when wrapping.
Enabled
Disabled
New line before )
#
Setting: php.format.rules.callParametersNewLineBeforeRightParen
Place a new line before the right closing parenthesis )
when wrapping.
Enabled
Disabled
Declaration parameters#
Wrap#
Setting: php.format.rules.declParametersWrap
Defines wrapping behavior for method or function declaration parameters.
Off
- No wrapping is appliedOn every item
- When this option is selected each declaration parameter is placed on a new line and properly indented if the arguments are split across multiple lines.
New line after (
#
Setting: php.format.rules.declParametersNewLineAfterLeftParen
Place a new line after the left opening parenthesis (
of function or method declaration header when wrapping.
Enabled
Disabled
New line before )
#
Setting: php.format.rules.declParametersNewLineBeforeRightParen
Place a new line before the right closing parenthesis )
of a function or method declaration header when wrapping.
Enabled
Disabled
Keep )
and {
on one line#
Setting: php.format.rules.declKeepRightParenAndOpenBraceOnOneLine
Keep the right closing parenthesis )
of a function or method declaration header on the one line as opening brace of the body {
.
Enabled
Disabled
while
statement#
New line after (
#
Setting: php.format.rules.whileStatementNewLineAfterLeftParen
Place a new line after the left opening parenthesis (
in a while
statement header if it's split across multiple lines.
Enabled
Disabled
New line before )
#
Setting: php.format.rules.whileStatementNewLineBeforeRightParen
Place a new line after the right closing parenthesis )
in a while
statement header if it's split across multiple lines.
Enabled
Disabled
for
statement#
Wrap#
Setting: php.format.rules.forStatementWrap
Defines wrapping behavior for for
statement.
Off
- No wrapping is appliedOn every item
- When this option is selected each item infor
statement is placed on a new line and properly indented if they are split across multiple lines.
New line after (
#
Setting: php.format.rules.forStatementNewLineAfterLeftParen
Place a new line after the left opening parenthesis (
in a for
statement header if it's split across multiple lines.
Enabled
Disabled
New line before )
#
Setting: php.format.rules.forStatementNewLineBeforeRightParen
Place a new line after the right closing parenthesis )
in a for
statement header if it's split across multiple lines.
Enabled
Disabled
if
statement#
New line after (
#
Setting: php.format.rules.ifStatementNewLineAfterLeftParen
Place a new line after the left opening parenthesis (
in a if
or elseif
statement header if it's split across multiple lines.
Enabled
Disabled
New line before )
#
Setting: php.format.rules.ifStatementNewLineBeforeRightParen
Place a new line after the right closing parenthesis )
in a if
or elseif
statement header if it's split across multiple lines.
Enabled
Disabled
else
on a new line#
Setting: php.format.rules.elseOnNewLine
Place else
on a new line.
Enabled
Disabled
switch
statement#
New line after (
#
Setting: php.format.rules.switchStatementNewLineAfterLeftParen
Place a new line after the left opening parenthesis (
in a switch
statement header if it's split across multiple lines.
Enabled
Disabled
New line before )
#
Setting: php.format.rules.switchStatementNewLineBeforeRightParen
Place a new line after the right closing parenthesis )
in a switch
statement header if it's split across multiple lines.
Enabled
Disabled
try
statement#
catch
on a new line#
Setting: php.format.rules.catchOnNewLine
Place catch
on a new line.
Enabled
Disabled
finally
on a new line#
Setting: php.format.rules.finallyOnNewLine
Place finally
on a new line.
Enabled
Disabled
Implements
list#
Wrap#
Setting: php.format.rules.implementsListWrap
Defines wrapping behavior for implements
list in type declarations.
Off
- No wrapping is appliedOn every item
- When this option is selected each interface inimplements
list is placed on a new line and properly indented if they are split across multiple lines.
New line after implements
#
Setting: php.format.rules.newLineAfterImplements
Place a new line after implements
in type declaration if the list of interfaces is split across multiple lines.
Enabled
Disabled
Group use
list#
Wrap#
Setting: php.format.rules.groupUseWrap
Defines wrapping behavior for group use
list in type declarations.
Off
- No wrapping is appliedOn every item
- When this option is selected each declaration in groupuse
list is placed on a new line and properly indented if they are split across multiple lines.
New line before first group use
declaration#
Setting: php.format.rules.groupUseNewLineBeforeFirstDeclaration
Place a new line before first group use
declaration if the list of declarations is split across multiple lines.
Enabled
Disabled
Assignment statement#
Align consecutive =
assignments.#
Setting: php.format.rules.alignConsecutiveAssignments
Automatically align consecutive =
assignments
Enabled
Disabled
Constants#
Align constants#
Setting: php.format.rules.alignConstants
Automatically align constant declarations
Enabled
Disabled
Enums#
Align enum cases#
Setting: php.format.rules.alignEnumCases
Automatically align assigned values in backed enumerations
Enabled
Disabled
Match expression#
Align match
arm bodies#
Setting: php.format.rules.alignMatchArmBodies
Automatically align the bodies (results) within match
expression arms
Enabled
Disabled
Conversions#
Array Initializers#
Add a comma after the last array element#
Setting: php.format.rules.addCommaAfterLastArrayElement
Automatically adds a comma after the last array element if it's not on a single line.
Enabled
Disabled
Parameters#
Add a comma after the last function call parameters#
Setting: php.format.rules.addCommaAfterLastCallParameter
Automatically adds a comma after the last function call parameter if it's not on a single line.
Enabled
Disabled
Add a comma after the last function declaration parameters#
Setting: php.format.rules.addCommaAfterLastDeclParameter
Automatically adds a comma after the last function or method declaration parameter if it's not on a single line.
Enabled
Disabled
Constants#
Boolean constant casing#
Setting: php.format.rules.booleanConstantCasing
Defines casing for true
and false
constants.
uppercase
- Changes the casing to upper caselowercase
- Changes the casing to lower casekeep
- Keeps the original casing
Null constant casing#
Setting: php.format.rules.nullConstantCasing
Defines casing for null
constant.
uppercase
- Changes the casing to upper caselowercase
- Changes the casing to lower casekeep
- Keeps the original casing