From 9c5daaf3688d4743f28bfd0c5f6e1c962e0e4ecf Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 17 Jun 2023 10:46:25 +0000 Subject: [PATCH] Updated Rector to commit b5cafa24ba8c2ac4d7a92341adb6af686dd0581f https://github.com/rectorphp/rector-src/commit/b5cafa24ba8c2ac4d7a92341adb6af686dd0581f [PhpParser] Remove parent lookup on BetterNodeFinder::findInstancesOfInFunctionLikeScoped() (#4253) --- src/Application/VersionResolver.php | 4 +-- src/PhpParser/Node/BetterNodeFinder.php | 33 ++++++++++++++----------- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 10 ++++---- vendor/composer/autoload_static.php | 8 +++--- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index e5db402367d..3b9e8142281 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 = 'aebf30995293f3ba2cb6bb2d10e3084f7e925a11'; + public const PACKAGE_VERSION = 'b5cafa24ba8c2ac4d7a92341adb6af686dd0581f'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-06-17 17:33:17'; + public const RELEASE_DATE = '2023-06-17 17:42:31'; /** * @var int */ diff --git a/src/PhpParser/Node/BetterNodeFinder.php b/src/PhpParser/Node/BetterNodeFinder.php index 19e4d4610bc..da40d579ba1 100644 --- a/src/PhpParser/Node/BetterNodeFinder.php +++ b/src/PhpParser/Node/BetterNodeFinder.php @@ -26,6 +26,7 @@ use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\While_; use PhpParser\NodeFinder; +use PhpParser\NodeTraverser; use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\Core\Exception\StopSearchException; use Rector\Core\NodeAnalyzer\ClassAnalyzer; @@ -36,6 +37,7 @@ use Rector\Core\Util\MultiInstanceofChecker; use Rector\Core\ValueObject\Application\File; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\Node\AttributeKey; +use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser; use RectorPrefix202306\Webmozart\Assert\Assert; /** * @see \Rector\Core\Tests\PhpParser\Node\BetterNodeFinder\BetterNodeFinderTest @@ -72,7 +74,12 @@ final class BetterNodeFinder * @var \Rector\Core\Provider\CurrentFileProvider */ private $currentFileProvider; - public function __construct(NodeFinder $nodeFinder, NodeNameResolver $nodeNameResolver, NodeComparator $nodeComparator, ClassAnalyzer $classAnalyzer, MultiInstanceofChecker $multiInstanceofChecker, CurrentFileProvider $currentFileProvider) + /** + * @readonly + * @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser + */ + private $simpleCallableNodeTraverser; + public function __construct(NodeFinder $nodeFinder, NodeNameResolver $nodeNameResolver, NodeComparator $nodeComparator, ClassAnalyzer $classAnalyzer, MultiInstanceofChecker $multiInstanceofChecker, CurrentFileProvider $currentFileProvider, SimpleCallableNodeTraverser $simpleCallableNodeTraverser) { $this->nodeFinder = $nodeFinder; $this->nodeNameResolver = $nodeNameResolver; @@ -80,6 +87,7 @@ final class BetterNodeFinder $this->classAnalyzer = $classAnalyzer; $this->multiInstanceofChecker = $multiInstanceofChecker; $this->currentFileProvider = $currentFileProvider; + $this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser; } /** * @deprecated Make use of child nodes instead @@ -335,23 +343,18 @@ final class BetterNodeFinder } /** @var T[] $foundNodes */ $foundNodes = []; - foreach ($types as $type) { - /** @var T[] $nodes */ - $nodes = $this->findInstanceOf((array) $functionLike->stmts, $type); - if ($nodes === []) { - continue; + $this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $functionLike->stmts, static function (Node $subNode) use($types, &$foundNodes) : ?int { + if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) { + return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } - foreach ($nodes as $key => $node) { - $parentFunctionLike = $this->findParentByTypes($node, [ClassMethod::class, Function_::class, Closure::class]); - if ($parentFunctionLike !== $functionLike) { - unset($nodes[$key]); + foreach ($types as $type) { + if ($subNode instanceof $type) { + $foundNodes[] = $subNode; + return null; } } - if ($nodes === []) { - continue; - } - $foundNodes = \array_merge($foundNodes, $nodes); - } + return null; + }); return $foundNodes; } /** diff --git a/vendor/autoload.php b/vendor/autoload.php index fb5b7efadf0..ce26acd7d21 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 ComposerAutoloaderInite73eb82043fbea86adc9ecc4b98e94ff::getLoader(); +return ComposerAutoloaderInit43e31d337be7dc1648be8823b77b2b05::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 458e29dff9d..08b3ad2ad91 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInite73eb82043fbea86adc9ecc4b98e94ff +class ComposerAutoloaderInit43e31d337be7dc1648be8823b77b2b05 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInite73eb82043fbea86adc9ecc4b98e94ff return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInite73eb82043fbea86adc9ecc4b98e94ff', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit43e31d337be7dc1648be8823b77b2b05', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInite73eb82043fbea86adc9ecc4b98e94ff', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit43e31d337be7dc1648be8823b77b2b05', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInite73eb82043fbea86adc9ecc4b98e94ff::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit43e31d337be7dc1648be8823b77b2b05::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInite73eb82043fbea86adc9ecc4b98e94ff::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit43e31d337be7dc1648be8823b77b2b05::$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 a67a4b5f00e..67c0aa1577a 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInite73eb82043fbea86adc9ecc4b98e94ff +class ComposerStaticInit43e31d337be7dc1648be8823b77b2b05 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3094,9 +3094,9 @@ class ComposerStaticInite73eb82043fbea86adc9ecc4b98e94ff public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInite73eb82043fbea86adc9ecc4b98e94ff::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInite73eb82043fbea86adc9ecc4b98e94ff::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInite73eb82043fbea86adc9ecc4b98e94ff::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit43e31d337be7dc1648be8823b77b2b05::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit43e31d337be7dc1648be8823b77b2b05::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit43e31d337be7dc1648be8823b77b2b05::$classMap; }, null, ClassLoader::class); }