Browse Source

BinaryOperatorSpacesFixer - Fix for alignment in `elseif`

John Paul E. Balandan, CPA 3 years ago
parent
commit
85ee54ec7f

+ 2 - 2
src/Fixer/Operator/BinaryOperatorSpacesFixer.php

@@ -543,7 +543,7 @@ $array = [
                 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);
 
@@ -569,7 +569,7 @@ $array = [
         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);
 

+ 18 - 0
tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php

@@ -1425,6 +1425,24 @@ m(
                 '<?php
 fn ($x = 1) => $x + 3;
 $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;
+}
 ',
             ],
         ];