Skip to content

Commit

Permalink
First iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Feb 4, 2024
1 parent 1fc90da commit 65ea695
Show file tree
Hide file tree
Showing 4 changed files with 706 additions and 0 deletions.
132 changes: 132 additions & 0 deletions doc/rules/control_structure/fully_multiline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
========================
Rule ``fully_multiline``
========================

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 (PHP >= 8.0 for ``parameters``
and ``match``).

Allowed values: a subset of ``['arguments', 'arrays', 'case', 'control_structures', 'match', 'parameters']``

Default value: ``['arrays']``

Examples
--------

Example #1
~~~~~~~~~~

*Default* configuration.

.. code-block:: diff
--- Original
+++ New
<?php
-array(1,
- 2);
+array(
+1,
+ 2
+);
Example #2
~~~~~~~~~~

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

.. code-block:: diff
--- Original
+++ New
<?php
-foo(1,
- 2);
+foo(
+1,
+ 2
+);
Example #3
~~~~~~~~~~

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

.. code-block:: diff
--- Original
+++ New
<?php
-if ($a
- && $b) {};
+if (
+$a
+ && $b
+) {};
Example #4
~~~~~~~~~~

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

.. code-block:: diff
--- Original
+++ New
<?php
switch ($foo) {
- case 0: case 1:
+ case 0:
+case 1:
return null;
};
Example #5
~~~~~~~~~~

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

.. code-block:: diff
--- Original
+++ New
<?php
-function foo($x,
- $y)
+function foo(
+$x,
+ $y
+)
{
}
Example #6
~~~~~~~~~~

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

.. code-block:: diff
--- Original
+++ New
<?php
match($x) {
- 1 => 1, 2 => 2
+ 1 => 1,
+2 => 2
};
References
----------

- Fixer class: `PhpCsFixer\\Fixer\\ControlStructure\\FullyMultilineFixer <./../../../src/Fixer/ControlStructure/FullyMultilineFixer.php>`_
- Test class: `PhpCsFixer\\Tests\\Fixer\\ControlStructure\\FullyMultilineFixerTest <./../../../tests/Fixer/ControlStructure/FullyMultilineFixerTest.php>`_

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
3 changes: 3 additions & 0 deletions doc/rules/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ Control Structure
- `empty_loop_condition <./control_structure/empty_loop_condition.rst>`_

Empty loop-condition must be in configured style.
- `fully_multiline <./control_structure/fully_multiline.rst>`_

Multi-line arrays, arguments list, parameters list, control structures, ``switch`` cases and ``match`` expressions should have one element by line.
- `include <./control_structure/include.rst>`_

Include/Require and file path should be divided with a single space. File path should not be placed within parentheses.
Expand Down

0 comments on commit 65ea695

Please sign in to comment.