Multi-line arrays, arguments list, parameters list, control structures,
switch
cases and match
expressions should have one element by line.
Which expression must have one element by line.
Allowed values: a subset of ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']
Default value: ['arrays', 'arguments', 'parameters', 'control_structures', 'case', 'match']
Default configuration.
--- Original
+++ New
<?php
-array(1,
- 2);
+array(
+1,
+ 2
+);
With configuration: ['elements' => ['arguments']]
.
--- Original
+++ New
<?php
-foo(1,
- 2);
+foo(
+1,
+ 2
+);
With configuration: ['elements' => ['control_structures']]
.
--- Original
+++ New
<?php
-if ($a
- && $b) {};
+if (
+$a
+ && $b
+) {};
With configuration: ['elements' => ['case']]
.
--- Original
+++ New
<?php
switch ($foo) {
- case 0: case 1:
+ case 0:
+case 1:
return null;
};
With configuration: ['elements' => ['parameters']]
.
--- Original
+++ New
<?php
-function foo($x,
- $y)
+function foo(
+$x,
+ $y
+)
{
}
With configuration: ['elements' => ['match']]
.
--- Original
+++ New
<?php
match($x) {
- 1 => 1, 2 => 2
+ 1 => 1,
+2 => 2
};
The rule is part of the following rule sets:
@PER with config:
['elements' => ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']]
@PER-CS with config:
['elements' => ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']]
@PER-CS1.0 with config:
['elements' => ['arguments', 'case', 'control_structures', 'match', 'parameters']]
@PER-CS2.0 with config:
['elements' => ['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']]
@PSR12 with config:
['elements' => ['arguments', 'case', 'control_structures', 'match', 'parameters']]
- Fixer class: PhpCsFixer\Fixer\ControlStructure\SingleExpressionPerLineFixer
- Test class: PhpCsFixer\Tests\Fixer\ControlStructure\SingleExpressionPerLineFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.