Skip to content

Commit

Permalink
BinaryOperatorSpacesFixer - Fix for alignment in elseif
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan committed Mar 9, 2022
1 parent d34ccf8 commit 0daf084
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Fixer/Operator/BinaryOperatorSpacesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ private function injectAlignmentPlaceholders(Tokens $tokens, int $startAt, int $
continue;
}

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

Expand All @@ -569,7 +569,7 @@ private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, int $startA
for ($index = $startAt; $index < $endAt; ++$index) {
$token = $tokens[$index];

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

Expand Down
18 changes: 18 additions & 0 deletions tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,24 @@ function ()
$f = 123;
',
],
[
'<?php
if (($c = count($array)) > 100) {
$_data = \'100+\';
} elseif (($c = count($array)) > 0) {
$_data = \'0+\';
}
'
],
[
'<?php
if (($c = count($array)) > 100) {
$closure = fn ($x = 1) => $x + 3;
} elseif (($c = count($array)) > 0) {
$closure = fn ($x = 1) => $x ** 3;
}
'
],
];
}

Expand Down

0 comments on commit 0daf084

Please sign in to comment.