diff --git a/rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php b/rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php index d73692c1763..dda67c20d75 100644 --- a/rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php +++ b/rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php @@ -118,10 +118,10 @@ private function shouldSkipIfAndReturn(If_ $if, Return_ $return) : bool if ($if->elseifs !== []) { return \true; } - if ($this->isElseSeparatedThenIf($if)) { + if (!$this->isIfWithSingleReturnExpr($if)) { return \true; } - if (!$this->isIfWithSingleReturnExpr($if)) { + if ($this->isElseSeparatedThenIf($if)) { return \true; } /** @var Return_ $ifInnerNode */ @@ -181,10 +181,18 @@ private function isElseSeparatedThenIf(If_ $if) : bool return \false; } if (\count($if->else->stmts) !== 1) { - return \false; + return \true; } $onlyStmt = $if->else->stmts[0]; - return $onlyStmt instanceof If_; + if (!$onlyStmt instanceof Return_ || !$onlyStmt->expr instanceof Expr) { + return \true; + } + if ($this->valueResolver->isTrueOrFalse($onlyStmt->expr)) { + /** @var Return_ $ifReturn */ + $ifReturn = $if->stmts[0]; + return $this->nodeComparator->areNodesEqual($onlyStmt->expr, $ifReturn->expr); + } + return \true; } private function isIfWithSingleReturnExpr(If_ $if) : bool { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index ff51932915e..008e6760c34 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'cb4ccd650eba6b43ac07da13e53b816a4119fad1'; + public const PACKAGE_VERSION = '203651aaf1c615c345620c5069c15755bde08227'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-10-11 08:57:33'; + public const RELEASE_DATE = '2024-10-11 13:18:42'; /** * @var int */