diff --git a/rules-tests/EarlyReturn/Rector/If_/RemoveAlwaysElseRector/Fixture/assign_in_if_else_before.php.inc b/rules-tests/EarlyReturn/Rector/If_/RemoveAlwaysElseRector/Fixture/assign_in_if_else_before.php.inc new file mode 100644 index 00000000000..42fb9655102 --- /dev/null +++ b/rules-tests/EarlyReturn/Rector/If_/RemoveAlwaysElseRector/Fixture/assign_in_if_else_before.php.inc @@ -0,0 +1,55 @@ + +----- + diff --git a/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php b/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php index 52fbbc5521f..51aa5f531ff 100644 --- a/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php +++ b/rules/EarlyReturn/Rector/If_/RemoveAlwaysElseRector.php @@ -132,6 +132,10 @@ private function doesLastStatementBreakFlow(If_ | ElseIf_ $node): bool { $lastStmt = end($node->stmts); + if ($lastStmt instanceof If_ && $lastStmt->else instanceof Else_) { + return $this->doesLastStatementBreakFlow($lastStmt); + } + return ! ($lastStmt instanceof Return_ || $lastStmt instanceof Throw_ || $lastStmt instanceof Continue_