Skip to content

Commit

Permalink
fix: TrailingCommaInMultilineFixer - handle trailing comma in langu…
Browse files Browse the repository at this point in the history
…age constructs (#7989)
  • Loading branch information
OndraM committed May 7, 2024
1 parent c3af946 commit 4b71d6d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
if (
$fixParameters
&& (
$tokens[$prevIndex]->isGivenKind(T_STRING) && $tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION)
|| $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION])
$tokens[$prevIndex]->isGivenKind(T_STRING)
&& $tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION)
|| $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION, T_ISSET, T_UNSET, T_LIST])
)
) {
$this->fixBlock($tokens, $index);
Expand Down
32 changes: 32 additions & 0 deletions tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,38 @@ public static function provideFix80Cases(): iterable
['elements' => [TrailingCommaInMultilineFixer::ELEMENTS_PARAMETERS]],
];

yield 'function-like language constructs' => [
'<?php
isset(
$a,
$b,
);
unset(
$a,
$b,
);
list(
$a,
$b,
) = $foo;
',
'<?php
isset(
$a,
$b
);
unset(
$a,
$b
);
list(
$a,
$b
) = $foo;
',
['elements' => [TrailingCommaInMultilineFixer::ELEMENTS_PARAMETERS]],
];

yield 'match' => [
'<?php
$m = match ($a) {
Expand Down

0 comments on commit 4b71d6d

Please sign in to comment.