Browse Source

bug #5610 BracesFixer - fix braces of match expression (Leprechaunz)

This PR was squashed before being merged into the 2.18 branch.

Discussion
----------

BracesFixer - fix braces of match expression

Fixes #5581

Commits
-------

8a92984ce BracesFixer - fix braces of match expression
Dariusz Ruminski 3 years ago
parent
commit
524b57de7b
2 changed files with 31 additions and 0 deletions
  1. 5 0
      src/Fixer/Basic/BracesFixer.php
  2. 26 0
      tests/Fixer/Basic/BracesFixerTest.php

+ 5 - 0
src/Fixer/Basic/BracesFixer.php

@@ -819,6 +819,11 @@ class Foo
             T_SWITCH,
             T_SWITCH,
         ];
         ];
 
 
+        // @TODO: drop condition when PHP 8.0+ is required
+        if (\defined('T_MATCH')) {
+            $tokens['match'] = T_MATCH;
+        }
+
         return $tokens;
         return $tokens;
     }
     }
 
 

+ 26 - 0
tests/Fixer/Basic/BracesFixerTest.php

@@ -5475,4 +5475,30 @@ if ($a) foreach ($b as $c): ?>
 <?php endforeach; ?>',
 <?php endforeach; ?>',
         ];
         ];
     }
     }
+
+    /**
+     * @requires PHP 8.0
+     *
+     * @param string $input
+     * @param string $expected
+     *
+     * @dataProvider provideFix80Cases
+     */
+    public function testFix80($expected, $input)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFix80Cases()
+    {
+        yield 'match' => [
+            '<?php echo match ($x) {
+    1, 2 => "Same for 1 and 2",
+};',
+            '<?php echo match($x)
+{
+    1, 2 => "Same for 1 and 2",
+};',
+        ];
+    }
 }
 }