Skip to content

Commit

Permalink
bug: Align all the arrows inside the same array (#6590)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Nov 21, 2022
1 parent 663f3fc commit ad0a87e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Expand Up @@ -514,7 +514,7 @@ private function fixAlignment(Tokens $tokens, array $toAlign): void
}
}

$tokens->setCode($this->replacePlaceholders($tokensClone, $alignStrategy));
$tokens->setCode($this->replacePlaceholders($tokensClone, $alignStrategy, $tokenContent));
}
}

Expand Down Expand Up @@ -755,7 +755,7 @@ private function fixWhiteSpaceBeforeOperator(Tokens $tokens, int $index, string
/**
* Look for group of placeholders and provide vertical alignment.
*/
private function replacePlaceholders(Tokens $tokens, string $alignStrategy): string
private function replacePlaceholders(Tokens $tokens, string $alignStrategy, string $tokenContent): string
{
$tmpCode = $tokens->generateCode();

Expand All @@ -774,7 +774,7 @@ private function replacePlaceholders(Tokens $tokens, string $alignStrategy): str
foreach ($lines as $index => $line) {
if (substr_count($line, $placeholder) > 0) {
$groups[$groupIndex][] = $index;
} else {
} elseif ('=>' !== $tokenContent) {
++$groupIndex;
$groups[$groupIndex] = [];
}
Expand Down
14 changes: 7 additions & 7 deletions tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php
Expand Up @@ -1711,7 +1711,7 @@ public function provideAlignDoubleArrowCases(): array
"foo" => "bar",
"foofoo" => 42,
]),
"baz" => "OK",
"baz" => "OK",
]);',
'<?php
return new JsonResponse([
Expand Down Expand Up @@ -1854,7 +1854,7 @@ public function provideAlignDoubleArrowCases(): array
1 => 2,
22 => 3,
],
100 => [
100 => [
1 => 2,
22 => 3,
]
Expand All @@ -1875,8 +1875,8 @@ public function provideAlignDoubleArrowCases(): array
[
'<?php
$a = array(
0 => 1,
10 => array(
0 => 1,
10 => array(
1 => 2,
22 => 3,
),
Expand Down Expand Up @@ -1936,7 +1936,7 @@ public function provideAlignDoubleArrowCases(): array
20 => 22,
30 => 33,
40
=>
=>
44,
);',
'<?php
Expand Down Expand Up @@ -2005,8 +2005,8 @@ public function provideAlignDoubleArrowCases(): array
'<?php
$array = array(
"bazab" => b(array(
1 => 2,
5 => [
1 => 2,
5 => [
6 => 7,
8 => 9,
],
Expand Down

0 comments on commit ad0a87e

Please sign in to comment.