From 0b31eebd0c3859deb47bf07a9986d5728e3b6a9a Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 20 Feb 2019 12:32:07 +0100 Subject: [PATCH] [PHP] Add ContinueToBreakInSwitchRector --- config/level/php/php52.yaml | 1 + .../Switch_/ContinueToBreakInSwitchRector.php | 76 +++++++++++++++++++ .../ContinueToBreakInSwitchRectorTest.php | 22 ++++++ .../Fixture/fixture.php.inc | 35 +++++++++ .../Fixture/skip_nested.php.inc | 19 +++++ 5 files changed, 153 insertions(+) create mode 100644 packages/Php/src/Rector/Switch_/ContinueToBreakInSwitchRector.php create mode 100644 packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/ContinueToBreakInSwitchRectorTest.php create mode 100644 packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/fixture.php.inc create mode 100644 packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/skip_nested.php.inc diff --git a/config/level/php/php52.yaml b/config/level/php/php52.yaml index dc9f6a7354e..9372b6b2b2a 100644 --- a/config/level/php/php52.yaml +++ b/config/level/php/php52.yaml @@ -1,2 +1,3 @@ services: Rector\Php\Rector\Property\VarToPublicPropertyRector: ~ + Rector\Php\Rector\Switch_\ContinueToBreakInSwitchRector: ~ diff --git a/packages/Php/src/Rector/Switch_/ContinueToBreakInSwitchRector.php b/packages/Php/src/Rector/Switch_/ContinueToBreakInSwitchRector.php new file mode 100644 index 00000000000..d2e1a5881fa --- /dev/null +++ b/packages/Php/src/Rector/Switch_/ContinueToBreakInSwitchRector.php @@ -0,0 +1,76 @@ +cases as $case) { + foreach ($case->stmts as $key => $caseStmt) { + if ($caseStmt instanceof Continue_) { + $case->stmts[$key] = new Break_(); + } + } + } + + return $node; + } +} diff --git a/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/ContinueToBreakInSwitchRectorTest.php b/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/ContinueToBreakInSwitchRectorTest.php new file mode 100644 index 00000000000..5e34f7afaf7 --- /dev/null +++ b/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/ContinueToBreakInSwitchRectorTest.php @@ -0,0 +1,22 @@ +doTestFilesWithoutAutoload([ + __DIR__ . '/Fixture/fixture.php.inc', + __DIR__ . '/Fixture/skip_nested.php.inc', + ]); + } + + protected function getRectorClass(): string + { + return ContinueToBreakInSwitchRector::class; + } +} diff --git a/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/fixture.php.inc b/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/fixture.php.inc new file mode 100644 index 00000000000..0592a7cfddf --- /dev/null +++ b/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/fixture.php.inc @@ -0,0 +1,35 @@ + +----- + diff --git a/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/skip_nested.php.inc b/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/skip_nested.php.inc new file mode 100644 index 00000000000..5be2d24fae0 --- /dev/null +++ b/packages/Php/tests/Rector/Switch_/ContinueToBreakInSwitchRector/Fixture/skip_nested.php.inc @@ -0,0 +1,19 @@ +