Customize Formatting
Respecting specific coding guidelines is crucial for maintaining a consistent codebase. In case the Code Style does not fit your needs, you can customize specific formatting rules. The settings bellow override behaviour set with the "php.format.codestyle"
style.
Settings: php.format.rules.*
License: PREMIUM.
Customize Settings in VS Code Settings UI
Browse through all the custom rules in Visual Studio Code Settings UI. Open command palette (Ctrl+Shift+P
) and type Preferences: Open User Settings (UI)
. Then search for php.format
and you will see all the available settings, including examples.
Indentation
IndentBraces: Gets value indicating whether to indent braces
VSCode Setting: php.format.rules.indentBraces
.editorconfig
Directive: php_format_indentBraces
true | false |
|
|
Spacing
Space after cast: Insert a space after a cast operator.
VSCode Setting: php.format.rules.spaceAfterCast
.editorconfig
Directive: php_format_spaceAfterCast
true | false |
|
|
Space after unary not !
:
Insert a space after a unary not operator.
VSCode Setting: php.format.rules.spaceAfterUnaryNot
.editorconfig
Directive: php_format_spaceAfterUnaryNot
true | false |
|
|
Space around concatenation .
:
Insert a space around concatenation operator.
VSCode Setting: php.format.rules.spaceAroundConcatenation
.editorconfig
Directive: php_format_spaceAroundConcatenation
true | false |
|
|
Space before colon :
in control flow statements:
Insert a space before colon in control flow blocks.
VSCode Setting: php.format.rules.spaceBeforeColonInControlStatements
.editorconfig
Directive: php_format_spaceBeforeColonInControlStatements
true | false |
|
|
Space before colon :
in return type:
Insert a space before colon in a return type
VSCode Setting: php.format.rules.spaceBeforeColonInReturnType
.editorconfig
Directive: php_format_spaceBeforeColonInReturnType
true | false |
|
|
Space before parentheses in arrow functions: Insert a space before arrow function parentheses.
VSCode Setting: php.format.rules.spaceBeforeParenthesesInArrowFunctions
.editorconfig
Directive: php_format_spaceBeforeParenthesesInArrowFunctions
true | false |
|
|
Space before parentheses in function calls: Insert a space before parentheses in method, function and constructor call parentheses.
VSCode Setting: php.format.rules.spaceBeforeParenthesesInCalls
.editorconfig
Directive: php_format_spaceBeforeParenthesesInCalls
true | false |
|
|
Space before parentheses in control statements: Insert a space before parentheses in control statements.
VSCode Setting: php.format.rules.spaceBeforeParenthesesInControlStatements
.editorconfig
Directive: php_format_spaceBeforeParenthesesInControlStatements
true | false |
|
|
Space before parentheses in declarations: Insert a space before parentheses in method, function and constructor declaration parentheses.
VSCode Setting: php.format.rules.spaceBeforeParenthesesInDeclarations
.editorconfig
Directive: php_format_spaceBeforeParenthesesInDeclarations
true | false |
|
|
Space within array initializer parentheses: Insert a space within array initializer parentheses.
VSCode Setting: php.format.rules.spaceWithinArrayInitilizersParens
.editorconfig
Directive: php_format_spaceWithinArrayInitilizersParens
true | false |
|
|
Space within brackets []
:
Insert a space within brackets.
VSCode Setting: php.format.rules.spaceWithinBrackets
.editorconfig
Directive: php_format_spaceWithinBrackets
true | false |
|
|
Space within brackets []
around expression:
Insert a space within brackets around expression.
VSCode Setting: php.format.rules.spaceWithinBracketsAroundExpression
.editorconfig
Directive: php_format_spaceWithinBracketsAroundExpression
true | false |
|
|
Space within call parentheses: Insert a space within method, function and constructor call parentheses.
VSCode Setting: php.format.rules.spaceWithinCallParens
.editorconfig
Directive: php_format_spaceWithinCallParens
true | false |
|
|
Space within catch
parentheses:
Insert a space within catch
statement header parentheses.
VSCode Setting: php.format.rules.spaceWithinCatchParens
.editorconfig
Directive: php_format_spaceWithinCatchParens
true | false |
|
|
Space within declaration parentheses: Insert a space within method, function and constructor declaration parentheses.
VSCode Setting: php.format.rules.spaceWithinDeclParens
.editorconfig
Directive: php_format_spaceWithinDeclParens
true | false |
|
|
Space within parentheses around expression: Insert a space within parentheses around expression.
VSCode Setting: php.format.rules.spaceWithinExpressionParens
.editorconfig
Directive: php_format_spaceWithinExpressionParens
true | false |
|
|
Space within for
parentheses:
Insert a space within for
statement header parentheses.
VSCode Setting: php.format.rules.spaceWithinForParens
.editorconfig
Directive: php_format_spaceWithinForParens
true | false |
|
|
Space within foreach
parentheses:
Insert a space within foreach
statement header parentheses.
VSCode Setting: php.format.rules.spaceWithinForeachParens
.editorconfig
Directive: php_format_spaceWithinForeachParens
true | false |
|
|
Space within if
parentheses:
Insert a space within if
statement header parentheses.
VSCode Setting: php.format.rules.spaceWithinIfParens
.editorconfig
Directive: php_format_spaceWithinIfParens
true | false |
|
|
Space within switch
parentheses:
Insert a space within switch
statement header parentheses.
VSCode Setting: php.format.rules.spaceWithinSwitchParens
.editorconfig
Directive: php_format_spaceWithinSwitchParens
true | false |
|
|
Space within while
parentheses:
Insert a space within while
statement header parentheses.
VSCode Setting: php.format.rules.spaceWithinWhileParens
.editorconfig
Directive: php_format_spaceWithinWhileParens
true | false |
|
|
NewLines
catch
on a new line:
Place catch
on a new line.
VSCode Setting: php.format.rules.catchOnNewLine
.editorconfig
Directive: php_format_catchOnNewLine
true | false |
|
|
else
on a new line:
Place else
on a new line.
VSCode Setting: php.format.rules.elseOnNewLine
.editorconfig
Directive: php_format_elseOnNewLine
true | false |
|
|
Insert final newline: Inserts final newline at the end of a file.
VSCode Setting: php.format.rules.endWithNewLine
.editorconfig
Directive: php_format_endWithNewLine
finally
on a new line:
Place finally
on a new line.
VSCode Setting: php.format.rules.finallyOnNewLine
.editorconfig
Directive: php_format_finallyOnNewLine
true | false |
|
|
Open brace on a new line for anonymous classes:
Place open brace {
on a new line for anonymous classes.
VSCode Setting: php.format.rules.openBraceOnNewLineForAnonymousClasses
.editorconfig
Directive: php_format_openBraceOnNewLineForAnonymousClasses
true | false |
|
|
Open brace on a new line for blocks:
Place open brace {
on a new line for all types of code blocks, except for those controlled by other formatting rules.
VSCode Setting: php.format.rules.openBraceOnNewLineForBlocks
.editorconfig
Directive: php_format_openBraceOnNewLineForBlocks
true | false |
|
|
Open brace on a new line for functions:
Place open brace {
on a new line for methods, functions and constructors.
VSCode Setting: php.format.rules.openBraceOnNewLineForFunctions
.editorconfig
Directive: php_format_openBraceOnNewLineForFunctions
true | false |
|
|
Open brace on a new line for lambda functions:
Place open brace {
on a new line for lambda functions.
VSCode Setting: php.format.rules.openBraceOnNewLineForLambdas
.editorconfig
Directive: php_format_openBraceOnNewLineForLambdas
true | false |
|
|
Open brace on a new line for namespaces:
Place open brace {
on a new line for namespace declarations.
VSCode Setting: php.format.rules.openBraceOnNewLineForNamespaces
.editorconfig
Directive: php_format_openBraceOnNewLineForNamespaces
true | false |
|
|
Open brace on a new line for types:
Place open brace {
on a new line for types.
VSCode Setting: php.format.rules.openBraceOnNewLineForTypes
.editorconfig
Directive: php_format_openBraceOnNewLineForTypes
true | false |
|
|
Wrapping
Align consecutive = assignments.:
Automatically align consecutive =
assignments.
VSCode Setting: php.format.rules.alignConsecutiveAssignments
.editorconfig
Directive: php_format_alignConsecutiveAssignments
true | false |
|
|
Align constants: Automatically align constant declarations
VSCode Setting: php.format.rules.alignConstants
.editorconfig
Directive: php_format_alignConstants
true | false |
|
|
Align enum cases: Automatically align assigned values in backed enumerations
VSCode Setting: php.format.rules.alignEnumCases
.editorconfig
Directive: php_format_alignEnumCases
true | false |
|
|
Align match
arm bodies:
Automatically align the bodies (results) within match
expression arms
VSCode Setting: php.format.rules.alignMatchArmBodies
.editorconfig
Directive: php_format_alignMatchArmBodies
true | false |
|
|
Align properties: Automatically align properties declarations
VSCode Setting: php.format.rules.alignProperties
.editorconfig
Directive: php_format_alignProperties
true | false |
|
|
Align key-value pairs:
Automatically align =>
operators.
VSCode Setting: php.format.rules.arrayInitializersAlignKeyValuePairs
.editorconfig
Directive: php_format_arrayInitializersAlignKeyValuePairs
true | false |
|
|
New line after last element: Place a new line after the last element when wrapping.
VSCode Setting: php.format.rules.arrayInitializersNewLineAfterLastElement
.editorconfig
Directive: php_format_arrayInitializersNewLineAfterLastElement
true | false |
|
|
New line before first element: Place a new line before the first array element when wrapping.
VSCode Setting: php.format.rules.arrayInitializersNewLineBeforeFirstElement
.editorconfig
Directive: php_format_arrayInitializersNewLineBeforeFirstElement
true | false |
|
|
Wrap: 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.
VSCode Setting: php.format.rules.arrayInitializersWrap
.editorconfig
Directive: php_format_arrayInitializersWrap
New line after (
:
Place a new line after the left opening parenthesis (
when wrapping.
VSCode Setting: php.format.rules.callParametersNewLineAfterLeftParen
.editorconfig
Directive: php_format_callParametersNewLineAfterLeftParen
true | false |
|
|
New line before )
:
Place a new line before the right closing parenthesis )
when wrapping.
VSCode Setting: php.format.rules.callParametersNewLineBeforeRightParen
.editorconfig
Directive: php_format_callParametersNewLineBeforeRightParen
true | false |
|
|
Wrap: 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.
VSCode Setting: php.format.rules.callParametersWrap
.editorconfig
Directive: php_format_callParametersWrap
;
on a new line:
Place ;
on a new line after the last element in the chained method call when wrapping.
VSCode Setting: php.format.rules.chainedMethodCallsSemicolonOnNewLine
.editorconfig
Directive: php_format_chainedMethodCallsSemicolonOnNewLine
true | false |
|
|
Wrap: Defines wrapping behavior for chained method calls.
Off
- No wrapping is appliedAlways
- When this option is selected each method call is placed on a new line and properly indented.
VSCode Setting: php.format.rules.chainedMethodCallsWrap
.editorconfig
Directive: php_format_chainedMethodCallsWrap
Compact empty body into {}
:
Transform empty body into {}
and keep it at the same line as a previous symbol, separated by single space.
VSCode Setting: php.format.rules.declCompactEmptyBody
.editorconfig
Directive: php_format_declCompactEmptyBody
true | false |
|
|
Keep )
and {
on one line:
Keep the right closing parenthesis )
of a function or method declaration header on the one line as opening brace of the body {
.
VSCode Setting: php.format.rules.declKeepRightParenAndOpenBraceOnOneLine
.editorconfig
Directive: php_format_declKeepRightParenAndOpenBraceOnOneLine
true | false |
|
|
New line after (
:
Place a new line after the left opening parenthesis (
of function or method declaration header when wrapping.
VSCode Setting: php.format.rules.declParametersNewLineAfterLeftParen
.editorconfig
Directive: php_format_declParametersNewLineAfterLeftParen
true | false |
|
|
New line before )
:
Place a new line before the right closing parenthesis )
of a function or method declaration header when wrapping.
VSCode Setting: php.format.rules.declParametersNewLineBeforeRightParen
.editorconfig
Directive: php_format_declParametersNewLineBeforeRightParen
true | false |
|
|
Wrap: 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.
VSCode Setting: php.format.rules.declParametersWrap
.editorconfig
Directive: php_format_declParametersWrap
New line after (
:
Place a new line after the left opening parenthesis (
in a for
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.forStatementNewLineAfterLeftParen
.editorconfig
Directive: php_format_forStatementNewLineAfterLeftParen
true | false |
|
|
New line before )
:
Place a new line after the right closing parenthesis )
in a for
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.forStatementNewLineBeforeRightParen
.editorconfig
Directive: php_format_forStatementNewLineBeforeRightParen
true | false |
|
|
Wrap:
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.
VSCode Setting: php.format.rules.forStatementWrap
.editorconfig
Directive: php_format_forStatementWrap
New line before first group use
declaration:
Place a new line before first group use
declaration if the list of declarations is split across multiple lines.
VSCode Setting: php.format.rules.groupUseNewLineBeforeFirstDeclaration
.editorconfig
Directive: php_format_groupUseNewLineBeforeFirstDeclaration
true | false |
|
|
Wrap:
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.
VSCode Setting: php.format.rules.groupUseWrap
.editorconfig
Directive: php_format_groupUseWrap
New line after (
:
Place a new line after the left opening parenthesis (
in a if
or elseif
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.ifStatementNewLineAfterLeftParen
.editorconfig
Directive: php_format_ifStatementNewLineAfterLeftParen
true | false |
|
|
New line before )
:
Place a new line after the right closing parenthesis )
in a if
or elseif
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.ifStatementNewLineBeforeRightParen
.editorconfig
Directive: php_format_ifStatementNewLineBeforeRightParen
true | false |
|
|
Wrap:
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.
VSCode Setting: php.format.rules.implementsListWrap
.editorconfig
Directive: php_format_implementsListWrap
Heredoc/Nowdoc Content Indentation: Ensures heredoc and nowdoc content lines are indented one level past the declaration's scope.
VSCode Setting: php.format.rules.indentHeredoc
.editorconfig
Directive: php_format_indentHeredoc
true | false |
|
|
Inline Heredoc/Nowdoc Declaration: Place heredoc and nowdoc on the same line as declaring variable
VSCode Setting: php.format.rules.inlineHeredoc
.editorconfig
Directive: php_format_inlineHeredoc
true | false |
|
|
Keep classes on one line: Clasess are kept on one line.
VSCode Setting: php.format.rules.keepClassesOnOneLine
.editorconfig
Directive: php_format_keepClassesOnOneLine
true | false |
|
|
Keep control statements on one line: Control statements are kept on one line.
VSCode Setting: php.format.rules.keepControlStatementsOnOneLine
.editorconfig
Directive: php_format_keepControlStatementsOnOneLine
true | false |
|
|
Keep functions on one line: Functions and methods are kept on one line.
VSCode Setting: php.format.rules.keepFunctionsOnOneLine
.editorconfig
Directive: php_format_keepFunctionsOnOneLine
true | false |
|
|
New line after implements
:
Place a new line after implements
in type declaration if the list of interfaces is split across multiple lines.
VSCode Setting: php.format.rules.newLineAfterImplements
.editorconfig
Directive: php_format_newLineAfterImplements
true | false |
|
|
New line after (
:
Place a new line after the left opening parenthesis (
in a switch
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.switchStatementNewLineAfterLeftParen
.editorconfig
Directive: php_format_switchStatementNewLineAfterLeftParen
true | false |
|
|
New line before )
:
Place a new line after the right closing parenthesis )
in a switch
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.switchStatementNewLineBeforeRightParen
.editorconfig
Directive: php_format_switchStatementNewLineBeforeRightParen
true | false |
|
|
New line after (
:
Place a new line after the left opening parenthesis (
in a while
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.whileStatementNewLineAfterLeftParen
.editorconfig
Directive: php_format_whileStatementNewLineAfterLeftParen
true | false |
|
|
New line before )
:
Place a new line after the right closing parenthesis )
in a while
statement header if it's split across multiple lines.
VSCode Setting: php.format.rules.whileStatementNewLineBeforeRightParen
.editorconfig
Directive: php_format_whileStatementNewLineBeforeRightParen
true | false |
|
|
Conversions
Add a comma after the last array element: Automatically adds a comma after the last array element if it's not on a single line.
VSCode Setting: php.format.rules.addCommaAfterLastArrayElement
.editorconfig
Directive: php_format_addCommaAfterLastArrayElement
Add a comma after the last function call parameters: Automatically adds a comma after the last function call parameter if it's not on a single line.
VSCode Setting: php.format.rules.addCommaAfterLastCallParameter
.editorconfig
Directive: php_format_addCommaAfterLastCallParameter
Add a comma after the last function declaration parameters: Automatically adds a comma after the last function or method declaration parameter if it's not on a single line.
VSCode Setting: php.format.rules.addCommaAfterLastDeclParameter
.editorconfig
Directive: php_format_addCommaAfterLastDeclParameter
Boolean constant casing:
Defines casing for true
and false
constants.
uppercase
- Changes the casing to upper caselowercase
- Changes the casing to lower casekeep
- Keeps the original casing
VSCode Setting: php.format.rules.booleanConstantCasing
.editorconfig
Directive: php_format_booleanConstantCasing
lowercase | uppercase |
|
|
Null constant casing:
Defines casing for null
constant.
uppercase
- Changes the casing to upper caselowercase
- Changes the casing to lower casekeep
- Keeps the original casing
VSCode Setting: php.format.rules.nullConstantCasing
.editorconfig
Directive: php_format_nullConstantCasing
lowercase | uppercase |
|
|
BlankLines
Blank lines after class: Defines the number of blank lines after a class declaration.
VSCode Setting: php.format.rules.blankLinesAfterClass
.editorconfig
Directive: php_format_blankLinesAfterClass
Blank lines after class body: Defines the number of blank lines after a class body.
VSCode Setting: php.format.rules.blankLinesAfterClassBody
.editorconfig
Directive: php_format_blankLinesAfterClassBody
Blank lines after function: Defines the number of blank lines after a function declaration.
VSCode Setting: php.format.rules.blankLinesAfterFunction
.editorconfig
Directive: php_format_blankLinesAfterFunction
Blank lines after method: Defines the number of blank lines after a method declaration.
VSCode Setting: php.format.rules.blankLinesAfterMethod
.editorconfig
Directive: php_format_blankLinesAfterMethod
Blank lines after namespace: Defines the number of blank lines after a namespace declaration.
VSCode Setting: php.format.rules.blankLinesAfterNamespace
.editorconfig
Directive: php_format_blankLinesAfterNamespace
Blank lines after use statements: Defines the number of blank lines after 'use' statements.
VSCode Setting: php.format.rules.blankLinesAfterUseStatements
.editorconfig
Directive: php_format_blankLinesAfterUseStatements
Blank lines before class: Defines the number of blank lines before a class declaration.
VSCode Setting: php.format.rules.blankLinesBeforeClass
.editorconfig
Directive: php_format_blankLinesBeforeClass
Blank lines before class body: Defines the number of blank lines before a class body.
VSCode Setting: php.format.rules.blankLinesBeforeClassBody
.editorconfig
Directive: php_format_blankLinesBeforeClassBody
Blank lines before function: Defines the number of blank lines before a function declaration.
VSCode Setting: php.format.rules.blankLinesBeforeFunction
.editorconfig
Directive: php_format_blankLinesBeforeFunction
Blank lines before function body: Defines the number of blank lines before a function body.
VSCode Setting: php.format.rules.blankLinesBeforeFunctionBody
.editorconfig
Directive: php_format_blankLinesBeforeFunctionBody
Blank lines before method: Defines the number of blank lines before a method declaration.
VSCode Setting: php.format.rules.blankLinesBeforeMethod
.editorconfig
Directive: php_format_blankLinesBeforeMethod
Blank lines before method body: Defines the number of blank lines before a method body.
VSCode Setting: php.format.rules.blankLinesBeforeMethodBody
.editorconfig
Directive: php_format_blankLinesBeforeMethodBody
Blank lines before namespace: Defines the number of blank lines before a namespace declaration.
VSCode Setting: php.format.rules.blankLinesBeforeNamespace
.editorconfig
Directive: php_format_blankLinesBeforeNamespace
Blank lines before use statements: Defines the number of blank lines before 'use' statements.
VSCode Setting: php.format.rules.blankLinesBeforeUseStatements
.editorconfig
Directive: php_format_blankLinesBeforeUseStatements
Maximum blank lines in code: Defines the maximum number of consecutive blank lines allowed in the code.
VSCode Setting: php.format.rules.maxBlankLines
.editorconfig
Directive: php_format_maxBlankLines