Skip to content

Commit

Permalink
fix: TrailingCommaInMultilineFixer - language constructs should be …
Browse files Browse the repository at this point in the history
…covered by arguments, not parameters (#7990)
  • Loading branch information
OndraM committed May 7, 2024
1 parent 4b71d6d commit 6a98688
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php
Expand Up @@ -142,7 +142,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
$prevPrevIndex = $tokens->getPrevMeaningfulToken($prevIndex);

if ($fixArguments
&& $tokens[$prevIndex]->equalsAny([']', [T_CLASS], [T_STRING], [T_VARIABLE], [T_STATIC]])
&& $tokens[$prevIndex]->equalsAny([']', [T_CLASS], [T_STRING], [T_VARIABLE], [T_STATIC], [T_ISSET], [T_UNSET], [T_LIST]])
&& !$tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION)
) {
$this->fixBlock($tokens, $index);
Expand All @@ -155,7 +155,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
&& (
$tokens[$prevIndex]->isGivenKind(T_STRING)
&& $tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION)
|| $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION, T_ISSET, T_UNSET, T_LIST])
|| $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION])
)
) {
$this->fixBlock($tokens, $index);
Expand Down
64 changes: 32 additions & 32 deletions tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php
Expand Up @@ -530,6 +530,38 @@ function a()
['elements' => [TrailingCommaInMultilineFixer::ELEMENTS_ARGUMENTS]],
];

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_ARGUMENTS]],
];

yield [
'<?php
array(
Expand Down Expand Up @@ -674,38 +706,6 @@ 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 6a98688

Please sign in to comment.