Braces must be placed as configured.
Allow anonymous functions to have opening and closing braces on the same line.
Allowed types: bool
Default value: true
Allow anonymous classes to have opening and closing braces on the same line.
Allowed types: bool
Default value: true
The position of the opening brace of anonymous classes‘ body.
Allowed values: 'next_line_unless_newline_at_signature_end' and 'same_line'
Default value: 'same_line'
The position of the opening brace of anonymous functions‘ body.
Allowed values: 'next_line_unless_newline_at_signature_end' and 'same_line'
Default value: 'same_line'
The position of the opening brace of classes‘ body.
Allowed values: 'next_line_unless_newline_at_signature_end' and 'same_line'
Default value: 'next_line_unless_newline_at_signature_end'
The position of the opening brace of control structures‘ body.
Allowed values: 'next_line_unless_newline_at_signature_end' and 'same_line'
Default value: 'same_line'
The position of the opening brace of functions‘ body.
Allowed values: 'next_line_unless_newline_at_signature_end' and 'same_line'
Default value: 'next_line_unless_newline_at_signature_end'
Default configuration.
--- Original
+++ New
<?php
-class Foo {
+class Foo
+{
}
-function foo() {
+function foo()
+{
}
-$foo = function()
-{
+$foo = function() {
};
-if (foo())
-{
+if (foo()) {
bar();
}
-$foo = new class
-{
+$foo = new class {
};With configuration: ['control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end'].
--- Original
+++ New
<?php
-if (foo()) {
+if (foo())
+{
bar();
}With configuration: ['functions_opening_brace' => 'same_line'].
--- Original
+++ New
<?php
-function foo()
-{
+function foo() {
}With configuration: ['anonymous_functions_opening_brace' => 'next_line_unless_newline_at_signature_end'].
--- Original
+++ New
<?php
-$foo = function () {
+$foo = function ()
+{
};With configuration: ['classes_opening_brace' => 'same_line'].
--- Original
+++ New
<?php
-class Foo
-{
+class Foo {
}With configuration: ['anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end'].
--- Original
+++ New
<?php
-$foo = new class {
+$foo = new class
+{
};With configuration: ['allow_single_line_empty_anonymous_classes' => true].
--- Original
+++ New
<?php
$foo = new class { };
-$bar = new class { private $baz; };
+$bar = new class {
+private $baz;
+};With configuration: ['allow_single_line_anonymous_functions' => true].
--- Original
+++ New
<?php
$foo = function () { return true; };
-$bar = function () { $result = true;
- return $result; };
+$bar = function () {
+$result = true;
+ return $result;
+};The rule is part of the following rule sets:
@PER with config:
['allow_single_line_empty_anonymous_classes' => true]@PER-CS with config:
['allow_single_line_empty_anonymous_classes' => true]@PER-CS1.0 with config:
['allow_single_line_empty_anonymous_classes' => true]@PER-CS2.0 with config:
['allow_single_line_empty_anonymous_classes' => true]@PSR12 with config:
['allow_single_line_empty_anonymous_classes' => true]@PhpCsFixer with config:
['allow_single_line_anonymous_functions' => true, 'allow_single_line_empty_anonymous_classes' => true]@Symfony with config:
['allow_single_line_anonymous_functions' => true, 'allow_single_line_empty_anonymous_classes' => true]
- Fixer class: PhpCsFixer\Fixer\Basic\BracesPositionFixer
- Test class: PhpCsFixer\Tests\Fixer\Basic\BracesPositionFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.