Skip to content

Commit

Permalink
bug #5610 BracesFixer - fix braces of match expression (Leprechaunz)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 2.18 branch.

Discussion
----------

BracesFixer - fix braces of match expression

Fixes #5581

Commits
-------

8a92984 BracesFixer - fix braces of match expression
  • Loading branch information
keradus committed Apr 11, 2021
2 parents 35aa5f4 + 8a92984 commit 524b57d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Fixer/Basic/BracesFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,11 @@ private function getControlTokens()
T_SWITCH,
];

// @TODO: drop condition when PHP 8.0+ is required
if (\defined('T_MATCH')) {
$tokens['match'] = T_MATCH;
}

return $tokens;
}

Expand Down
26 changes: 26 additions & 0 deletions tests/Fixer/Basic/BracesFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5475,4 +5475,30 @@ public function provideFixAlternativeSyntaxCases()
<?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",
};',
];
}
}

0 comments on commit 524b57d

Please sign in to comment.