Skip to content

Latest commit

 

History

History
158 lines (111 loc) · 3.08 KB

single_expression_per_line.rst

File metadata and controls

158 lines (111 loc) · 3.08 KB

Rule single_expression_per_line

Multi-line arrays, arguments list, parameters list, control structures, switch cases and match expressions should have one element by line.

Configuration

elements

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']

Examples

Example #1

Default configuration.

--- Original
+++ New
 <?php
-array(1,
-    2);
+array(
+1,
+    2
+);

Example #2

With configuration: ['elements' => ['arguments']].

--- Original
+++ New
 <?php
-foo(1,
-    2);
+foo(
+1,
+    2
+);

Example #3

With configuration: ['elements' => ['control_structures']].

--- Original
+++ New
 <?php
-if ($a
-    && $b) {};
+if (
+$a
+    && $b
+) {};

Example #4

With configuration: ['elements' => ['case']].

--- Original
+++ New
 <?php
 switch ($foo) {
-    case 0: case 1:
+    case 0:
+case 1:
         return null;
     };

Example #5

With configuration: ['elements' => ['parameters']].

--- Original
+++ New
 <?php
-function foo($x,
-    $y)
+function foo(
+$x,
+    $y
+)
 {
 }

Example #6

With configuration: ['elements' => ['match']].

--- Original
+++ New
 <?php
 match($x) {
-    1 => 1, 2 => 2
+    1 => 1,
+2 => 2
 };

Rule sets

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']]

References

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.