Fork me on GitHub
a Sensio Labs Product

I ate three cookies πŸͺ (v3.40.2) edition

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.

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

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

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

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

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

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

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

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

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

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

--- Original
+++ New
 <?php
 sample(
     <<<EOD
         foo
-        EOD
-    ,
+        EOD,
     'bar'
 );

Rule setsΒΆ

The rule is part of the following rule sets:

  • @PER

  • @PER-CS

  • @PER-CS1.0 with config:

    ['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']

  • @PER-CS2.0

  • @PHP73Migration with config:

    ['after_heredoc' => true]

  • @PHP74Migration with config:

    ['after_heredoc' => true]

  • @PHP80Migration with config:

    ['after_heredoc' => true]

  • @PHP81Migration with config:

    ['after_heredoc' => true]

  • @PHP82Migration with config:

    ['after_heredoc' => true]

  • @PHP83Migration with config:

    ['after_heredoc' => true]

  • @PSR2 with config:

    ['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']

  • @PSR12 with config:

    ['attribute_placement' => 'ignore', 'on_multiline' => 'ensure_fully_multiline']

  • @PhpCsFixer with config:

    ['on_multiline' => 'ensure_fully_multiline']

  • @Symfony with config:

    ['on_multiline' => 'ignore']

Source classΒΆ

PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer