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 Settigs 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
Setting: php.format.rules.indentBraces
IndentBraces: Gets value indicating whether to indent braces
true | false |
|
|
Spacing
Setting: php.format.rules.spaceAfterCast
Space after cast: Insert a space after a cast operator.
true | false |
|
|
Setting: php.format.rules.spaceAfterUnaryNot
Space after unary not !
:
Insert a space after a unary not operator.
true | false |
|
|
Setting: php.format.rules.spaceAroundConcatenation
Space around concatenation .
:
Insert a space around concatenation operator.
true | false |
|
|
Setting: php.format.rules.spaceBeforeColonInControlStatements
Space before colon :
in control flow statements:
Insert a space before colon in control flow blocks.
true | false |
|
|
Setting: php.format.rules.spaceBeforeColonInReturnType
Space before colon :
in return type:
Insert a space before colon in a return type
true | false |
|
|
Setting: php.format.rules.spaceBeforeParenthesesInArrowFunctions
Space before parentheses in arrow functions: Insert a space before arrow function parentheses.
true | false |
|
|
Setting: php.format.rules.spaceBeforeParenthesesInCalls
Space before parentheses in function calls: Insert a space before parentheses in method, function and constructor call parentheses.
true | false |
|
|
Setting: php.format.rules.spaceBeforeParenthesesInControlStatements
Space before parentheses in control statements: Insert a space before parentheses in control statements.
true | false |
|
|
Setting: php.format.rules.spaceBeforeParenthesesInDeclarations
Space before parentheses in declarations: Insert a space before parentheses in method, function and constructor declaration parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinArrayInitilizersParens
Space within array initializer parentheses: Insert a space within array initializer parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinBrackets
Space within brackets []
:
Insert a space within brackets.
true | false |
|
|
Setting: php.format.rules.spaceWithinBracketsAroundExpression
Space within brackets []
around expression:
Insert a space within brackets around expression.
true | false |
|
|
Setting: php.format.rules.spaceWithinCallParens
Space within call parentheses: Insert a space within method, function and constructor call parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinCatchParens
Space within catch
parentheses:
Insert a space within catch
statement header parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinDeclParens
Space within declaration parentheses: Insert a space within method, function and constructor declaration parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinExpressionParens
Space within parentheses around expression: Insert a space within parentheses around expression.
true | false |
|
|
Setting: php.format.rules.spaceWithinForParens
Space within for
parentheses:
Insert a space within for
statement header parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinForeachParens
Space within foreach
parentheses:
Insert a space within foreach
statement header parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinIfParens
Space within if
parentheses:
Insert a space within if
statement header parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinSwitchParens
Space within switch
parentheses:
Insert a space within switch
statement header parentheses.
true | false |
|
|
Setting: php.format.rules.spaceWithinWhileParens
Space within while
parentheses:
Insert a space within while
statement header parentheses.
true | false |
|
|
NewLines
Setting: php.format.rules.catchOnNewLine
catch
on a new line:
Place catch
on a new line.
true | false |
|
|
Setting: php.format.rules.elseOnNewLine
else
on a new line:
Place else
on a new line.
true | false |
|
|
Setting: php.format.rules.endWithNewLine
Insert final newline: Inserts final newline at the end of a file.
Setting: php.format.rules.finallyOnNewLine
finally
on a new line:
Place finally
on a new line.
true | false |
|
|
Setting: php.format.rules.openBraceOnNewLineForAnonymousClasses
Open brace on a new line for anonymous classes:
Place open brace {
on a new line for anonymous classes.
true | false |
|
|
Setting: php.format.rules.openBraceOnNewLineForBlocks
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.
true | false |
|
|
Setting: php.format.rules.openBraceOnNewLineForFunctions
Open brace on a new line for functions:
Place open brace {
on a new line for methods, functions and constructors.
true | false |
|
|
Setting: php.format.rules.openBraceOnNewLineForLambdas
Open brace on a new line for lambda functions:
Place open brace {
on a new line for lambda functions.
true | false |
|
|
Setting: php.format.rules.openBraceOnNewLineForNamespaces
Open brace on a new line for namespaces:
Place open brace {
on a new line for namespace declarations.
true | false |
|
|
Setting: php.format.rules.openBraceOnNewLineForTypes
Open brace on a new line for types:
Place open brace {
on a new line for types.
true | false |
|
|
Wrapping
Setting: php.format.rules.alignConsecutiveAssignments
Align consecutive = assignments.:
Automatically align consecutive =
assignments.
true | false |
|
|
Setting: php.format.rules.alignConstants
Align constants: Automatically align constant declarations
true | false |
|
|
Setting: php.format.rules.alignEnumCases
Align enum cases: Automatically align assigned values in backed enumerations
true | false |
|
|
Setting: php.format.rules.alignMatchArmBodies
Align match
arm bodies:
Automatically align the bodies (results) within match
expression arms
true | false |
|
|
Setting: php.format.rules.alignProperties
Align properties: Automatically align properties declarations
true | false |
|
|
Setting: php.format.rules.arrayInitializersAlignKeyValuePairs
Align key-value pairs:
Automatically align =>
operators.
true | false |
|
|
Setting: php.format.rules.arrayInitializersNewLineAfterLastElement
New line after last element: Place a new line after the last element when wrapping.
true | false |
|
|
Setting: php.format.rules.arrayInitializersNewLineBeforeFirstElement
New line before first element: Place a new line before the first array element when wrapping.
true | false |
|
|
Setting: php.format.rules.arrayInitializersWrap
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.
Setting: php.format.rules.callParametersNewLineAfterLeftParen
New line after (
:
Place a new line after the left opening parenthesis (
when wrapping.
true | false |
|
|
Setting: php.format.rules.callParametersNewLineBeforeRightParen
New line before )
:
Place a new line before the right closing parenthesis )
when wrapping.
true | false |
|
|
Setting: php.format.rules.callParametersWrap
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.
Setting: php.format.rules.chainedMethodCallsSemicolonOnNewLine
;
on a new line:
Place ;
on a new line after the last element in the chained method call when wrapping.
true | false |
|
|
Setting: php.format.rules.chainedMethodCallsWrap
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.
Setting: php.format.rules.declCompactEmptyBody
Compact empty body into {}
:
Transform empty body into {}
and keep it at the same line as a previous symbol, separated by single space.
true | false |
|
|
Setting: php.format.rules.declKeepRightParenAndOpenBraceOnOneLine
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 {
.
true | false |
|
|
Setting: php.format.rules.declParametersNewLineAfterLeftParen
New line after (
:
Place a new line after the left opening parenthesis (
of function or method declaration header when wrapping.
true | false |
|
|
Setting: php.format.rules.declParametersNewLineBeforeRightParen
New line before )
:
Place a new line before the right closing parenthesis )
of a function or method declaration header when wrapping.
true | false |
|
|
Setting: php.format.rules.declParametersWrap
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.
Setting: php.format.rules.forStatementNewLineAfterLeftParen
New line after (
:
Place a new line after the left opening parenthesis (
in a for
statement header if it's split across multiple lines.
true | false |
|
|
Setting: php.format.rules.forStatementNewLineBeforeRightParen
New line before )
:
Place a new line after the right closing parenthesis )
in a for
statement header if it's split across multiple lines.
true | false |
|
|
Setting: php.format.rules.forStatementWrap
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.
Setting: php.format.rules.groupUseNewLineBeforeFirstDeclaration
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.
true | false |
|
|
Setting: php.format.rules.groupUseWrap
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.
Setting: php.format.rules.ifStatementNewLineAfterLeftParen
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.
true | false |
|
|
Setting: php.format.rules.ifStatementNewLineBeforeRightParen
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.
true | false |
|
|
Setting: php.format.rules.implementsListWrap
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.
Setting: php.format.rules.keepClassesOnOneLine
Keep classes on one line: Clasess are kept on one line.
true | false |
|
|
Setting: php.format.rules.keepControlStatementsOnOneLine
Keep control statements on one line: Control statements are kept on one line.
true | false |
|
|
Setting: php.format.rules.keepFunctionsOnOneLine
Keep functions on one line: Functions and methods are kept on one line.
true | false |
|
|
Setting: php.format.rules.newLineAfterImplements
New line after implements
:
Place a new line after implements
in type declaration if the list of interfaces is split across multiple lines.
true | false |
|
|
Setting: php.format.rules.switchStatementNewLineAfterLeftParen
New line after (
:
Place a new line after the left opening parenthesis (
in a switch
statement header if it's split across multiple lines.
true | false |
|
|
Setting: php.format.rules.switchStatementNewLineBeforeRightParen
New line before )
:
Place a new line after the right closing parenthesis )
in a switch
statement header if it's split across multiple lines.
true | false |
|
|
Setting: php.format.rules.whileStatementNewLineAfterLeftParen
New line after (
:
Place a new line after the left opening parenthesis (
in a while
statement header if it's split across multiple lines.
true | false |
|
|
Setting: php.format.rules.whileStatementNewLineBeforeRightParen
New line before )
:
Place a new line after the right closing parenthesis )
in a while
statement header if it's split across multiple lines.
true | false |
|
|
Conversions
Setting: php.format.rules.addCommaAfterLastArrayElement
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.
Setting: php.format.rules.addCommaAfterLastCallParameter
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.
Setting: php.format.rules.addCommaAfterLastDeclParameter
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.
Setting: php.format.rules.booleanConstantCasing
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
lowercase | uppercase |
|
|
Setting: php.format.rules.nullConstantCasing
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
lowercase | uppercase |
|
|
BlankLines
Setting: php.format.rules.blankLinesAfterClass
Blank lines after class: Defines the number of blank lines after a class declaration.
Setting: php.format.rules.blankLinesAfterClassBody
Blank lines after class body: Defines the number of blank lines after a class body.
Setting: php.format.rules.blankLinesAfterFunction
Blank lines after function: Defines the number of blank lines after a function declaration.
Setting: php.format.rules.blankLinesAfterMethod
Blank lines after method: Defines the number of blank lines after a method declaration.
Setting: php.format.rules.blankLinesAfterNamespace
Blank lines after namespace: Defines the number of blank lines after a namespace declaration.
Setting: php.format.rules.blankLinesAfterUseStatements
Blank lines after use statements: Defines the number of blank lines after 'use' statements.
Setting: php.format.rules.blankLinesBeforeClass
Blank lines before class: Defines the number of blank lines before a class declaration.
Setting: php.format.rules.blankLinesBeforeClassBody
Blank lines before class body: Defines the number of blank lines before a class body.
Setting: php.format.rules.blankLinesBeforeFunction
Blank lines before function: Defines the number of blank lines before a function declaration.
Setting: php.format.rules.blankLinesBeforeFunctionBody
Blank lines before function body: Defines the number of blank lines before a function body.
Setting: php.format.rules.blankLinesBeforeMethod
Blank lines before method: Defines the number of blank lines before a method declaration.
Setting: php.format.rules.blankLinesBeforeMethodBody
Blank lines before method body: Defines the number of blank lines before a method body.
Setting: php.format.rules.blankLinesBeforeNamespace
Blank lines before namespace: Defines the number of blank lines before a namespace declaration.
Setting: php.format.rules.blankLinesBeforeUseStatements
Blank lines before use statements: Defines the number of blank lines before 'use' statements.
Setting: php.format.rules.maxBlankLines
Maximum blank lines in code: Defines the maximum number of consecutive blank lines allowed in the code.