123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- ==============================
- Rule ``method_argument_space``
- ==============================
- In method arguments and method call, there MUST NOT be a space before each comma
- and there MUST be one space after each comma. Argument lists MAY be split across
- multiple lines, where each subsequent line is indented once. When doing so, the
- first item in the list MUST be on the next line, and there MUST be only one
- argument per line.
- Description
- -----------
- This fixer covers rules defined in PSR2 ¶4.4, ¶4.6.
- Configuration
- -------------
- ``after_heredoc``
- ~~~~~~~~~~~~~~~~~
- Whether the whitespace between heredoc end and comma should be removed.
- Allowed types: ``bool``
- Default value: ``false``
- ``attribute_placement``
- ~~~~~~~~~~~~~~~~~~~~~~~
- Defines how to handle argument attributes when function definition is multiline.
- Allowed values: ``'ignore'``, ``'same_line'`` and ``'standalone'``
- Default value: ``'standalone'``
- ``keep_multiple_spaces_after_comma``
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Whether keep multiple spaces after comma.
- Allowed types: ``bool``
- Default value: ``false``
- ``on_multiline``
- ~~~~~~~~~~~~~~~~
- Defines how to handle function arguments lists that contain newlines.
- Allowed values: ``'ensure_fully_multiline'``, ``'ensure_single_line'`` and ``'ignore'``
- Default value: ``'ensure_fully_multiline'``
- Examples
- --------
- Example #1
- ~~~~~~~~~~
- *Default* configuration.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample($a=10,$b=20,$c=30) {}
- -sample(1, 2);
- +function sample($a=10, $b=20, $c=30) {}
- +sample(1, 2);
- Example #2
- ~~~~~~~~~~
- With configuration: ``['keep_multiple_spaces_after_comma' => false]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample($a=10,$b=20,$c=30) {}
- -sample(1, 2);
- +function sample($a=10, $b=20, $c=30) {}
- +sample(1, 2);
- Example #3
- ~~~~~~~~~~
- With configuration: ``['keep_multiple_spaces_after_comma' => true]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample($a=10,$b=20,$c=30) {}
- +function sample($a=10, $b=20, $c=30) {}
- sample(1, 2);
- Example #4
- ~~~~~~~~~~
- With configuration: ``['on_multiline' => 'ensure_fully_multiline']``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample($a=10,
- - $b=20,$c=30) {}
- -sample(1,
- - 2);
- +function sample(
- + $a=10,
- + $b=20,
- + $c=30
- +) {}
- +sample(
- + 1,
- + 2
- +);
- Example #5
- ~~~~~~~~~~
- With configuration: ``['on_multiline' => 'ensure_single_line']``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample(
- - $a=10,
- - $b=20,
- - $c=30
- -) {}
- -sample(
- - 1,
- - 2
- -);
- +function sample($a=10, $b=20, $c=30) {}
- +sample(1, 2);
- Example #6
- ~~~~~~~~~~
- With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => true]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample($a=10,
- - $b=20,$c=30) {}
- -sample(1,
- - 2);
- +function sample(
- + $a=10,
- + $b=20,
- + $c=30
- +) {}
- +sample(
- + 1,
- + 2
- +);
- sample('foo', 'foobarbaz', 'baz');
- sample('foobar', 'bar', 'baz');
- Example #7
- ~~~~~~~~~~
- With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'keep_multiple_spaces_after_comma' => false]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample($a=10,
- - $b=20,$c=30) {}
- -sample(1,
- - 2);
- -sample('foo', 'foobarbaz', 'baz');
- -sample('foobar', 'bar', 'baz');
- +function sample(
- + $a=10,
- + $b=20,
- + $c=30
- +) {}
- +sample(
- + 1,
- + 2
- +);
- +sample('foo', 'foobarbaz', 'baz');
- +sample('foobar', 'bar', 'baz');
- Example #8
- ~~~~~~~~~~
- With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'attribute_placement' => 'ignore']``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample(#[Foo] #[Bar] $a=10,
- - $b=20,$c=30) {}
- -sample(1, 2);
- +function sample(
- + #[Foo] #[Bar] $a=10,
- + $b=20,
- + $c=30
- +) {}
- +sample(1, 2);
- Example #9
- ~~~~~~~~~~
- With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'attribute_placement' => 'same_line']``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample(#[Foo]
- - #[Bar]
- - $a=10,
- - $b=20,$c=30) {}
- -sample(1, 2);
- +function sample(
- + #[Foo] #[Bar] $a=10,
- + $b=20,
- + $c=30
- +) {}
- +sample(1, 2);
- Example #10
- ~~~~~~~~~~~
- With configuration: ``['on_multiline' => 'ensure_fully_multiline', 'attribute_placement' => 'standalone']``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- -function sample(#[Foo] #[Bar] $a=10,
- - $b=20,$c=30) {}
- -sample(1, 2);
- +function sample(
- + #[Foo]
- + #[Bar]
- + $a=10,
- + $b=20,
- + $c=30
- +) {}
- +sample(1, 2);
- Example #11
- ~~~~~~~~~~~
- With configuration: ``['after_heredoc' => true]``.
- .. code-block:: diff
- --- Original
- +++ New
- <?php
- sample(
- <<<EOD
- foo
- - EOD
- - ,
- + EOD,
- 'bar'
- );
- Rule sets
- ---------
- The rule is part of the following rule sets:
- - `@PER <./../../ruleSets/PER.rst>`_
- - `@PER-CS <./../../ruleSets/PER-CS.rst>`_
- - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
- ``['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']``
- - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
- - `@PHP73Migration <./../../ruleSets/PHP73Migration.rst>`_ with config:
- ``['after_heredoc' => true]``
- - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_ with config:
- ``['after_heredoc' => true]``
- - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ with config:
- ``['after_heredoc' => true]``
- - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ with config:
- ``['after_heredoc' => true]``
- - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_ with config:
- ``['after_heredoc' => true]``
- - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_ with config:
- ``['after_heredoc' => true]``
- - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_ with config:
- ``['after_heredoc' => true]``
- - `@PSR2 <./../../ruleSets/PSR2.rst>`_ with config:
- ``['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']``
- - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
- ``['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']``
- - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
- ``['on_multiline' => 'ensure_fully_multiline']``
- - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
- ``['on_multiline' => 'ignore']``
- References
- ----------
- - Fixer class: `PhpCsFixer\\Fixer\\FunctionNotation\\MethodArgumentSpaceFixer <./../../../src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php>`_
- - Test class: `PhpCsFixer\\Tests\\Fixer\\FunctionNotation\\MethodArgumentSpaceFixerTest <./../../../tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php>`_
- The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.
|