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

bug: Align all the arrows inside the same array #6590

Merged
merged 1 commit into from
Nov 21, 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
6 changes: 3 additions & 3 deletions src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ public function provideAlignDoubleArrowCases(): array
"foo" => "bar",
"foofoo" => 42,
]),
"baz" => "OK",
"baz" => "OK",
]);',
'<?php
return new JsonResponse([
Expand Down Expand Up @@ -1850,7 +1850,7 @@ public function provideAlignDoubleArrowCases(): array
1 => 2,
22 => 3,
],
100 => [
100 => [
1 => 2,
22 => 3,
]
Expand All @@ -1871,8 +1871,8 @@ public function provideAlignDoubleArrowCases(): array
[
'<?php
$a = array(
0 => 1,
10 => array(
0 => 1,
10 => array(
1 => 2,
22 => 3,
),
Expand Down Expand Up @@ -1932,7 +1932,7 @@ public function provideAlignDoubleArrowCases(): array
20 => 22,
30 => 33,
40
=>
=>
44,
);',
'<?php
Expand Down Expand Up @@ -2001,8 +2001,8 @@ public function provideAlignDoubleArrowCases(): array
'<?php
$array = array(
"bazab" => b(array(
1 => 2,
5 => [
1 => 2,
5 => [
6 => 7,
8 => 9,
],
Expand Down