Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TrailingCommaInMultilineFixer - handle trailing comma in language constructs #7989

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@
if (
$fixParameters
&& (
$tokens[$prevIndex]->isGivenKind(T_STRING) && $tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION)
|| $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION])
$tokens[$prevIndex]->isGivenKind(T_STRING)

Check warning on line 156 in src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 mutation tests

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $this->fixBlock($tokens, $index); continue; } - if ($fixParameters && ($tokens[$prevIndex]->isGivenKind(T_STRING) && $tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION) || $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION, T_ISSET, T_UNSET, T_LIST]))) { + if ($fixParameters && ($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); } if ($fixMatch && $tokens[$prevIndex]->isGivenKind(T_MATCH)) {

Check warning on line 156 in src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 mutation tests

Escaped Mutant for Mutator "LogicalOrAllSubExprNegation": --- Original +++ New @@ @@ $this->fixBlock($tokens, $index); continue; } - if ($fixParameters && ($tokens[$prevIndex]->isGivenKind(T_STRING) && $tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION) || $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION, T_ISSET, T_UNSET, T_LIST]))) { + if ($fixParameters && (!($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); } if ($fixMatch && $tokens[$prevIndex]->isGivenKind(T_MATCH)) {
&& $tokens[$prevPrevIndex]->isGivenKind(T_FUNCTION)
|| $tokens[$prevIndex]->isGivenKind([T_FN, T_FUNCTION, T_ISSET, T_UNSET, T_LIST])
Wirone marked this conversation as resolved.
Show resolved Hide resolved
)
) {
$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