Rule trailing_comma_in_multiline¶
Arguments lists, array destructuring lists, arrays that are multi-line,
match-lines and parameters lists must have a trailing comma.
Configuration¶
after_heredoc¶
Whether a trailing comma should also be placed after heredoc end.
Allowed types: bool
Default value: false
elements¶
Where to fix multiline trailing comma (PHP >= 8.0 for parameters and
match).
Allowed values: a subset of ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']
Default value: ['arrays']
Examples¶
Example #1¶
Default configuration.
--- Original
+++ New
<?php
array(
1,
- 2
+ 2,
);
Example #2¶
With configuration: ['after_heredoc' => true].
--- Original
+++ New
<?php
$x = [
'foo',
<<<EOD
bar
- EOD
+ EOD,
];
Example #3¶
With configuration: ['elements' => ['arguments']].
--- Original
+++ New
<?php
foo(
1,
- 2
+ 2,
);
Example #4¶
With configuration: ['elements' => ['parameters']].
--- Original
+++ New
<?php
function foo(
$x,
- $y
+ $y,
)
{
}
Rule sets¶
The rule is part of the following rule sets:
@PER (deprecated) with config:
['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]@PER-CS with config:
['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]@PER-CS2.0 (deprecated) with config:
['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]@PER-CS2x0 with config:
['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]@PER-CS3.0 (deprecated) with config:
['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]@PER-CS3x0 with config:
['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays', 'match', 'parameters']]@PHP7x3Migration with config:
['after_heredoc' => true]@PHP7x4Migration with config:
['after_heredoc' => true]@PHP8x0Migration with config:
['after_heredoc' => true]@PHP8x1Migration with config:
['after_heredoc' => true]@PHP8x2Migration with config:
['after_heredoc' => true]@PHP8x3Migration with config:
['after_heredoc' => true]@PHP8x4Migration with config:
['after_heredoc' => true]@PHP8x5Migration with config:
['after_heredoc' => true]@PHP73Migration (deprecated) with config:
['after_heredoc' => true]@PHP74Migration (deprecated) with config:
['after_heredoc' => true]@PHP80Migration (deprecated) with config:
['after_heredoc' => true]@PHP81Migration (deprecated) with config:
['after_heredoc' => true]@PHP82Migration (deprecated) with config:
['after_heredoc' => true]@PHP83Migration (deprecated) with config:
['after_heredoc' => true]@PHP84Migration (deprecated) with config:
['after_heredoc' => true]@PHP85Migration (deprecated) with config:
['after_heredoc' => true]@PhpCsFixer with config:
['after_heredoc' => true, 'elements' => ['array_destructuring', 'arrays']]@Symfony with config:
['after_heredoc' => true, 'elements' => ['array_destructuring', 'arrays', 'match', 'parameters']]
References¶
Fixer class: PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer
Test class: PhpCsFixer\Tests\Fixer\ControlStructure\TrailingCommaInMultilineFixerTest
The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.