From 1f89bb9561f728dd1de07676b7b0eabe3c1295a8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 24 May 2023 10:04:51 +0000 Subject: [PATCH] Updated Rector to commit c050b66f9b9812f8f7735673e651deaccded0071 https://github.com/rectorphp/rector-src/commit/c050b66f9b9812f8f7735673e651deaccded0071 Refactor PARENT_NODE away from ListEachRector (#3946) --- rules/Php72/Rector/Assign/ListEachRector.php | 47 +++++++++----------- src/Application/VersionResolver.php | 4 +- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 10 ++--- vendor/composer/autoload_static.php | 8 ++-- 5 files changed, 32 insertions(+), 39 deletions(-) diff --git a/rules/Php72/Rector/Assign/ListEachRector.php b/rules/Php72/Rector/Assign/ListEachRector.php index be5a0940f19..3f2cd536358 100644 --- a/rules/Php72/Rector/Assign/ListEachRector.php +++ b/rules/Php72/Rector/Assign/ListEachRector.php @@ -13,8 +13,6 @@ use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\NodeManipulator\AssignManipulator; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\PostRector\Collector\NodesToAddCollector; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -30,15 +28,9 @@ final class ListEachRector extends AbstractRector implements MinPhpVersionInterf * @var \Rector\Core\NodeManipulator\AssignManipulator */ private $assignManipulator; - /** - * @readonly - * @var \Rector\PostRector\Collector\NodesToAddCollector - */ - private $nodesToAddCollector; - public function __construct(AssignManipulator $assignManipulator, NodesToAddCollector $nodesToAddCollector) + public function __construct(AssignManipulator $assignManipulator) { $this->assignManipulator = $assignManipulator; - $this->nodesToAddCollector = $nodesToAddCollector; } public function provideMinPhpVersion() : int { @@ -61,20 +53,24 @@ CODE_SAMPLE */ public function getNodeTypes() : array { - return [Assign::class]; + return [Expression::class]; } /** - * @param Assign $node + * @param Expression $node */ - public function refactor(Node $node) : ?Node + public function refactor(Node $node) { - if ($this->shouldSkip($node)) { + if (!$node->expr instanceof Assign) { + return null; + } + $assign = $node->expr; + if ($this->shouldSkipAssign($assign)) { return null; } /** @var List_ $listNode */ - $listNode = $node->var; + $listNode = $assign->var; /** @var FuncCall $eachFuncCall */ - $eachFuncCall = $node->expr; + $eachFuncCall = $assign->expr; // only key: list($key, ) = each($values); if ($listNode->items[0] instanceof ArrayItem && !$listNode->items[1] instanceof ArrayItem) { $keyFuncCall = $this->nodeFactory->createFuncCall('key', $eachFuncCall->args); @@ -83,10 +79,11 @@ CODE_SAMPLE // only value: list(, $value) = each($values); if ($listNode->items[1] instanceof ArrayItem && !$listNode->items[0] instanceof ArrayItem) { $nextFuncCall = $this->nodeFactory->createFuncCall('next', $eachFuncCall->args); - $this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $node); + // $this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $assign); $currentFuncCall = $this->nodeFactory->createFuncCall('current', $eachFuncCall->args); $secondArrayItem = $listNode->items[1]; - return new Assign($secondArrayItem->value, $currentFuncCall); + $currentAssign = new Assign($secondArrayItem->value, $currentFuncCall); + return [new Expression($currentAssign), new Expression($nextFuncCall)]; } // both: list($key, $value) = each($values); $currentFuncCall = $this->nodeFactory->createFuncCall('current', $eachFuncCall->args); @@ -94,27 +91,23 @@ CODE_SAMPLE if (!$secondArrayItem instanceof ArrayItem) { throw new ShouldNotHappenException(); } - $assign = new Assign($secondArrayItem->value, $currentFuncCall); - $this->nodesToAddCollector->addNodeAfterNode($assign, $node); + $currentAssign = new Assign($secondArrayItem->value, $currentFuncCall); + // $this->nodesToAddCollector->addNodeAfterNode($assign, $assign); $nextFuncCall = $this->nodeFactory->createFuncCall('next', $eachFuncCall->args); - $this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $node); + // $this->nodesToAddCollector->addNodeAfterNode($nextFuncCall, $node); $keyFuncCall = $this->nodeFactory->createFuncCall('key', $eachFuncCall->args); $firstArrayItem = $listNode->items[0]; if (!$firstArrayItem instanceof ArrayItem) { throw new ShouldNotHappenException(); } - return new Assign($firstArrayItem->value, $keyFuncCall); + $keyAssign = new Assign($firstArrayItem->value, $keyFuncCall); + return [new Expression($keyAssign), new Expression($currentAssign), new Expression($nextFuncCall)]; } - private function shouldSkip(Assign $assign) : bool + private function shouldSkipAssign(Assign $assign) : bool { if (!$this->assignManipulator->isListToEachAssign($assign)) { return \true; } - // assign should be top level, e.g. not in a while loop - $parentNode = $assign->getAttribute(AttributeKey::PARENT_NODE); - if (!$parentNode instanceof Expression) { - return \true; - } /** @var List_ $listNode */ $listNode = $assign->var; if (\count($listNode->items) !== 2) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 410ca98bd8f..f712f295913 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 = '279126145e995c4d0b39a60bd6fc5fff5799199e'; + public const PACKAGE_VERSION = 'c050b66f9b9812f8f7735673e651deaccded0071'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-05-24 09:38:51'; + public const RELEASE_DATE = '2023-05-24 10:00:13'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index f022580a79a..6fef8c4b31c 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 ComposerAutoloaderInit68fa97b402c8b0e8b73786dcfe58719b::getLoader(); +return ComposerAutoloaderInit6665049c1bf4f1bfd9e1d88569d19ca5::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 8d4f9536cfa..96a49a46164 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit68fa97b402c8b0e8b73786dcfe58719b +class ComposerAutoloaderInit6665049c1bf4f1bfd9e1d88569d19ca5 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit68fa97b402c8b0e8b73786dcfe58719b return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit68fa97b402c8b0e8b73786dcfe58719b', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit6665049c1bf4f1bfd9e1d88569d19ca5', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit68fa97b402c8b0e8b73786dcfe58719b', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit6665049c1bf4f1bfd9e1d88569d19ca5', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit68fa97b402c8b0e8b73786dcfe58719b::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit6665049c1bf4f1bfd9e1d88569d19ca5::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit68fa97b402c8b0e8b73786dcfe58719b::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit6665049c1bf4f1bfd9e1d88569d19ca5::$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 baf82afbe90..6dbe55c0c1c 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit68fa97b402c8b0e8b73786dcfe58719b +class ComposerStaticInit6665049c1bf4f1bfd9e1d88569d19ca5 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3106,9 +3106,9 @@ class ComposerStaticInit68fa97b402c8b0e8b73786dcfe58719b public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit68fa97b402c8b0e8b73786dcfe58719b::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit68fa97b402c8b0e8b73786dcfe58719b::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit68fa97b402c8b0e8b73786dcfe58719b::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit6665049c1bf4f1bfd9e1d88569d19ca5::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit6665049c1bf4f1bfd9e1d88569d19ca5::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit6665049c1bf4f1bfd9e1d88569d19ca5::$classMap; }, null, ClassLoader::class); }