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

[BinaryOperatorSpacesFixer] Fix align of = inside calls of methods #6112

Merged
merged 1 commit into from Feb 14, 2022
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
12 changes: 10 additions & 2 deletions src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Expand Up @@ -531,6 +531,11 @@ private function fixAlignment(Tokens $tokens, array $toAlign): void

private function injectAlignmentPlaceholders(Tokens $tokens, int $startAt, int $endAt, string $tokenContent): void
{
$functionKind = [T_FUNCTION];
if (\PHP_VERSION_ID >= 70400) {
$functionKind[] = T_FN;
}

for ($index = $startAt; $index < $endAt; ++$index) {
$token = $tokens[$index];

Expand All @@ -545,13 +550,16 @@ private function injectAlignmentPlaceholders(Tokens $tokens, int $startAt, int $
continue;
}

if ($token->isGivenKind(T_FUNCTION)) {
if ($token->isGivenKind($functionKind)) {
++$this->deepestLevel;
$index = $tokens->getNextTokenOfKind($index, ['(']);
$index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);

continue;
}

if ($token->equals('(')) {
if ($token->isGivenKind([T_FOREACH, T_FOR, T_WHILE, T_IF, T_SWITCH])) {
$index = $tokens->getNextMeaningfulToken($index);
$index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);

continue;
Expand Down
26 changes: 26 additions & 0 deletions tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php
Expand Up @@ -1401,6 +1401,32 @@ function b(
$a[$b] = array();
}',
],
[
'<?php
m(
function ()
{
$d["a"] = 1;
$d["abc"] = 2;
}
);
',
'<?php
m(
function ()
{
$d["a"] = 1;
$d["abc"] = 2;
}
);
',
],
[
'<?php
fn ($x = 1) => $x + 3;
$f = 123;
',
],
];
}

Expand Down