From 1f93d1a53a22c588022adb08cddf8f0b4e587364 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 11 Oct 2024 06:21:10 +0000 Subject: [PATCH] Updated Rector to commit 203651aaf1c615c345620c5069c15755bde08227 https://github.com/rectorphp/rector-src/commit/203651aaf1c615c345620c5069c15755bde08227 [CodeQuality] Skip else indirect return on SimplifyIfReturnBoolRector (#6371) --- .../Rector/If_/SimplifyIfReturnBoolRector.php | 16 ++++++++++++---- src/Application/VersionResolver.php | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php b/rules/CodeQuality/Rector/If_/SimplifyIfReturnBoolRector.php index d73692c17630..dda67c20d758 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 ff51932915ea..008e6760c341 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 */