Skip to content

fix: MethodArgumentSpaceFixer - fix nested calls for ensure_fully_multiline option#8469

Merged
kubawerlos merged 10 commits intoPHP-CS-Fixer:masterfrom
geecu:fix_nested_calls_multiline
Mar 3, 2025
Merged

fix: MethodArgumentSpaceFixer - fix nested calls for ensure_fully_multiline option#8469
kubawerlos merged 10 commits intoPHP-CS-Fixer:masterfrom
geecu:fix_nested_calls_multiline

Conversation

@geecu
Copy link
Copy Markdown
Contributor

@geecu geecu commented Mar 1, 2025

The inner function call is indented first and then it was ignored when the outer function call was being checked - only the function name god indented, leading to:

foo(
    $x,
    bar(
    $foo,
    $bar,
    $baz
)
);

The inner function call is indented first and then it was ignored when
the outer function call was being checked - only the function name
god indented, leading to:

```php
foo(
    $x,
    bar(
    $foo,
    $bar,
    $baz
)
);
@coveralls
Copy link
Copy Markdown

coveralls commented Mar 1, 2025

Coverage Status

coverage: 94.929% (-0.01%) from 94.939%
when pulling ec747ab on geecu:fix_nested_calls_multiline
into 6acce13 on PHP-CS-Fixer:master.


$expectedTokens = [T_LIST, T_FUNCTION, CT::T_USE_LAMBDA, T_FN, T_CLASS];

for ($index = $tokens->count() - 1; $index > 0; --$index) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ($index = $tokens->count() - 1; $index > 0; --$index) {
$tokenCount = $tokens->count();
for ($index = 1; $index < $tokenCount; ++$index) {

There is no need to introduce multilinedTokens, reversing this loop would be enough.

Gunther Konig added 4 commits March 1, 2025 19:06
The test would've failed just as well even if the inner function had
only two variables instead of three.
The test would've failed just as well even if the inner function had
only two variables instead of three.
@geecu
Copy link
Copy Markdown
Contributor Author

geecu commented Mar 3, 2025

@kubawerlos your suggestion works like a charm, I've removed $multilinedTokens and reversed to order of the loop:
ec747ab

Just in case, I've also added a test with two levels of nested calls to check that this is valid (it is).

@geecu geecu requested a review from kubawerlos March 3, 2025 13:44
@kubawerlos kubawerlos changed the title fix: nested calls ensure_fully_multiline fix: MethodArgumentSpaceFixer - fix nested calls for ensure_fully_multiline option Mar 3, 2025
@kubawerlos kubawerlos merged commit 395a33e into PHP-CS-Fixer:master Mar 3, 2025
@kubawerlos
Copy link
Copy Markdown
Member

Thank you @geecu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants