The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
You should use single_space_around_construct
, control_structure_braces
,
control_structure_continuation_position
, declare_parentheses
,
no_multiple_statements_per_line
, braces_position
,
statement_indentation
and no_extra_blank_lines
instead.
Whether single line anonymous class with empty body notation should be allowed.
Allowed types: bool
Default value: false
Whether single line lambda notation should be allowed.
Allowed types: bool
Default value: false
Whether the opening brace should be placed on "next" or "same" line after anonymous constructs (anonymous classes and lambda functions).
Allowed values: 'next'
and 'same'
Default value: 'same'
Whether the opening brace should be placed on "next" or "same" line after control structures.
Allowed values: 'next'
and 'same'
Default value: 'same'
Whether the opening brace should be placed on "next" or "same" line after classy constructs (non-anonymous classes, interfaces, traits, methods and non-lambda functions).
Allowed values: 'next'
and 'same'
Default value: 'next'
Default configuration.
--- Original
+++ New
<?php
-class Foo {
- public function bar($baz) {
- if ($baz = 900) echo "Hello!";
+class Foo
+{
+ public function bar($baz)
+ {
+ if ($baz = 900) {
+ echo "Hello!";
+ }
- if ($baz = 9000)
+ if ($baz = 9000) {
echo "Wait!";
+ }
- if ($baz == true)
- {
+ if ($baz == true) {
echo "Why?";
- }
- else
- {
+ } else {
echo "Ha?";
}
- if (is_array($baz))
- foreach ($baz as $b)
- {
+ if (is_array($baz)) {
+ foreach ($baz as $b) {
echo $b;
}
+ }
}
}
With configuration: ['allow_single_line_closure' => true]
.
--- Original
+++ New
<?php
$positive = function ($item) { return $item >= 0; };
$negative = function ($item) {
- return $item < 0; };
+ return $item < 0;
+};
With configuration: ['position_after_functions_and_oop_constructs' => 'same']
.
--- Original
+++ New
<?php
-class Foo
-{
- public function bar($baz)
- {
- if ($baz = 900) echo "Hello!";
+class Foo {
+ public function bar($baz) {
+ if ($baz = 900) {
+ echo "Hello!";
+ }
- if ($baz = 9000)
+ if ($baz = 9000) {
echo "Wait!";
+ }
- if ($baz == true)
- {
+ if ($baz == true) {
echo "Why?";
- }
- else
- {
+ } else {
echo "Ha?";
}
- if (is_array($baz))
- foreach ($baz as $b)
- {
+ if (is_array($baz)) {
+ foreach ($baz as $b) {
echo $b;
}
+ }
}
}
- Fixer class: PhpCsFixer\Fixer\Basic\BracesFixer
- Test class: PhpCsFixer\Tests\Fixer\Basic\BracesFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.