From dafb30ce80fc66a47beb36ca1f56bfd53a73713d Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 23 Sep 2023 20:12:11 +0700 Subject: [PATCH 1/2] [Php80] Mirror switch comment to match to ChangeSwitchToMatchRector --- rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php b/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php index af4e4345498..e827691617e 100644 --- a/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php +++ b/rules/Php80/Rector/Switch_/ChangeSwitchToMatchRector.php @@ -122,6 +122,7 @@ public function refactor(Node $node): ?Node $assign = new Assign($assignVar, $match); $node->stmts[$key] = new Expression($assign); + $this->mirrorComments($node->stmts[$key], $stmt); $hasChanged = true; @@ -133,6 +134,7 @@ public function refactor(Node $node): ?Node } $node->stmts[$key] = $isReturn ? new Return_($match) : new Expression($match); + $this->mirrorComments($node->stmts[$key], $stmt); $hasChanged = true; } From 57c6c60c80f2e3f48b7057073224e9cd06117ff1 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 23 Sep 2023 20:12:17 +0700 Subject: [PATCH 2/2] [Php80] Mirror switch comment to match to ChangeSwitchToMatchRector --- .../Fixture/copy_switch_comment.php.inc | 40 +++++++++++++++++++ .../copy_switch_comment_with_return.php.inc | 40 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment.php.inc create mode 100644 rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment_with_return.php.inc diff --git a/rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment.php.inc b/rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment.php.inc new file mode 100644 index 00000000000..4f14f4353a0 --- /dev/null +++ b/rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment.php.inc @@ -0,0 +1,40 @@ +lexer->lookahead['type']) { + case Lexer::T_DELETE: + $statement = $this->DeleteStatement(); + break; + + default: + $statement = $this->syntaxError('SELECT, UPDATE or DELETE'); + break; + } + } +} + +?> +----- +lexer->lookahead['type']) { + Lexer::T_DELETE => $this->DeleteStatement(), + default => $this->syntaxError('SELECT, UPDATE or DELETE'), + }; + } +} + +?> diff --git a/rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment_with_return.php.inc b/rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment_with_return.php.inc new file mode 100644 index 00000000000..b36aa9e09a2 --- /dev/null +++ b/rules-tests/Php80/Rector/Switch_/ChangeSwitchToMatchRector/Fixture/copy_switch_comment_with_return.php.inc @@ -0,0 +1,40 @@ + +----- + 1000, + default => 2000, + }; + } +} + +?>