From 9b3b24049effa69a52724b5716afeed85748cd1f Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 9 Apr 2023 03:06:57 +0000 Subject: [PATCH] Updated Rector to commit 83eef32f504c089d81d801d26a0355632bdc46b5 https://github.com/rectorphp/rector-src/commit/83eef32f504c089d81d801d26a0355632bdc46b5 [EarlyReturn] Reduce next attribute usage on ChangeAndIfToEarlyReturnRector (#3597) --- rules/EarlyReturn/NodeFactory/InvertedIfFactory.php | 12 ++---------- .../Rector/If_/ChangeAndIfToEarlyReturnRector.php | 8 ++++---- src/Application/VersionResolver.php | 4 ++-- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 10 +++++----- vendor/composer/autoload_static.php | 8 ++++---- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php b/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php index 9eddda1906e..62f526b312f 100644 --- a/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php +++ b/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php @@ -5,6 +5,7 @@ namespace Rector\EarlyReturn\NodeFactory; use PhpParser\Node; use PhpParser\Node\Expr; +use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Continue_; use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\Return_; @@ -39,10 +40,9 @@ final class InvertedIfFactory * @param Expr[] $conditions * @return If_[] */ - public function createFromConditions(If_ $if, array $conditions, Return_ $return) : array + public function createFromConditions(If_ $if, array $conditions, Return_ $return, ?Stmt $ifNextReturn) : array { $ifs = []; - $ifNextReturn = $this->getIfNextReturn($if); $stmt = $this->contextAnalyzer->isInLoop($if) && !$ifNextReturn instanceof Return_ ? [new Continue_()] : [$return]; if ($ifNextReturn instanceof Return_) { $stmt[0]->setAttribute(AttributeKey::COMMENTS, $ifNextReturn->getAttribute(AttributeKey::COMMENTS)); @@ -65,12 +65,4 @@ final class InvertedIfFactory return $node instanceof Return_ && $node->expr instanceof Expr; }); } - private function getIfNextReturn(If_ $if) : ?Return_ - { - $nextNode = $if->getAttribute(AttributeKey::NEXT_NODE); - if (!$nextNode instanceof Return_) { - return null; - } - return $nextNode; - } } diff --git a/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php b/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php index 2a44451da6a..99026d49ed7 100644 --- a/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php +++ b/rules/EarlyReturn/Rector/If_/ChangeAndIfToEarlyReturnRector.php @@ -144,7 +144,7 @@ CODE_SAMPLE $afterStmts = []; if (!$nextStmt instanceof Return_) { $afterStmts[] = $stmt->stmts[0]; - $node->stmts = \array_merge($newStmts, $this->processReplaceIfs($stmt, $booleanAndConditions, new Return_(), $afterStmts)); + $node->stmts = \array_merge($newStmts, $this->processReplaceIfs($stmt, $booleanAndConditions, new Return_(), $afterStmts, $nextStmt)); return $node; } // remove next node @@ -154,7 +154,7 @@ CODE_SAMPLE if ($this->isInLoopWithoutContinueOrBreak($stmt)) { $afterStmts[] = new Return_(); } - $changedStmts = $this->processReplaceIfs($stmt, $booleanAndConditions, $ifNextReturnClone, $afterStmts); + $changedStmts = $this->processReplaceIfs($stmt, $booleanAndConditions, $ifNextReturnClone, $afterStmts, $nextStmt); // update stmts $node->stmts = \array_merge($newStmts, $changedStmts); return $node; @@ -176,9 +176,9 @@ CODE_SAMPLE * @param Stmt[] $afters * @return Stmt[] */ - private function processReplaceIfs(If_ $if, array $conditions, Return_ $ifNextReturnClone, array $afters) : array + private function processReplaceIfs(If_ $if, array $conditions, Return_ $ifNextReturnClone, array $afters, ?Stmt $nextStmt) : array { - $ifs = $this->invertedIfFactory->createFromConditions($if, $conditions, $ifNextReturnClone); + $ifs = $this->invertedIfFactory->createFromConditions($if, $conditions, $ifNextReturnClone, $nextStmt); $this->mirrorComments($ifs[0], $if); $result = \array_merge($ifs, $afters); if ($if->stmts[0] instanceof Return_) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 37a0d7ff07e..5cf08546eb9 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 = 'cc30d2db2dcb4c5adacb7cf34edf25913be2bd01'; + public const PACKAGE_VERSION = '83eef32f504c089d81d801d26a0355632bdc46b5'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-04-09 01:23:06'; + public const RELEASE_DATE = '2023-04-09 10:03:03'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index d43a37ef98a..c1eddded11c 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d::getLoader(); +return ComposerAutoloaderInit59fe1b308651c754ec29d7c0bf08c532::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 7a57ba5ec57..35a0afc45cc 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d +class ComposerAutoloaderInit59fe1b308651c754ec29d7c0bf08c532 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit59fe1b308651c754ec29d7c0bf08c532', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit0ccf446dda2c38ddeb47fe0a6741726d', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit59fe1b308651c754ec29d7c0bf08c532', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index bb923892203..fb870875971 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d +class ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3137,9 +3137,9 @@ class ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit0ccf446dda2c38ddeb47fe0a6741726d::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit59fe1b308651c754ec29d7c0bf08c532::$classMap; }, null, ClassLoader::class); }