From c363d3ea16f61a995242d7a37e9625afa2e2bae3 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 17 Jun 2023 20:18:18 +0000 Subject: [PATCH] Updated Rector to commit 5f976fa8c3eccf209e17e16d36fb6eb68c782ab4 https://github.com/rectorphp/rector-src/commit/5f976fa8c3eccf209e17e16d36fb6eb68c782ab4 [ReadWrite] Remove parent lookup on LocalPropertyFetchReadNodeAnalyzer (#4263) --- .../LocalPropertyFetchReadNodeAnalyzer.php | 24 +++++++++++++------ src/Application/VersionResolver.php | 4 ++-- .../NodeFinder/PropertyFetchFinder.php | 17 +++++++------ vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 10 ++++---- vendor/composer/autoload_static.php | 8 +++---- 6 files changed, 39 insertions(+), 26 deletions(-) diff --git a/packages/ReadWrite/ReadNodeAnalyzer/LocalPropertyFetchReadNodeAnalyzer.php b/packages/ReadWrite/ReadNodeAnalyzer/LocalPropertyFetchReadNodeAnalyzer.php index 55e1f6a0da6..2d4a95dce3d 100644 --- a/packages/ReadWrite/ReadNodeAnalyzer/LocalPropertyFetchReadNodeAnalyzer.php +++ b/packages/ReadWrite/ReadNodeAnalyzer/LocalPropertyFetchReadNodeAnalyzer.php @@ -7,8 +7,10 @@ use PhpParser\Node\Expr; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Stmt\Class_; -use Rector\Core\PhpParser\Node\BetterNodeFinder; +use PHPStan\Reflection\ClassReflection; +use Rector\Core\PhpParser\ClassLikeAstResolver; use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder; +use Rector\Core\Reflection\ReflectionResolver; use Rector\NodeNameResolver\NodeNameResolver; use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface; /** @@ -33,15 +35,21 @@ final class LocalPropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterf private $nodeNameResolver; /** * @readonly - * @var \Rector\Core\PhpParser\Node\BetterNodeFinder + * @var \Rector\Core\Reflection\ReflectionResolver */ - private $betterNodeFinder; - public function __construct(\Rector\ReadWrite\ReadNodeAnalyzer\JustReadExprAnalyzer $justReadExprAnalyzer, PropertyFetchFinder $propertyFetchFinder, NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder) + private $reflectionResolver; + /** + * @readonly + * @var \Rector\Core\PhpParser\ClassLikeAstResolver + */ + private $classLikeAstResolver; + public function __construct(\Rector\ReadWrite\ReadNodeAnalyzer\JustReadExprAnalyzer $justReadExprAnalyzer, PropertyFetchFinder $propertyFetchFinder, NodeNameResolver $nodeNameResolver, ReflectionResolver $reflectionResolver, ClassLikeAstResolver $classLikeAstResolver) { $this->justReadExprAnalyzer = $justReadExprAnalyzer; $this->propertyFetchFinder = $propertyFetchFinder; $this->nodeNameResolver = $nodeNameResolver; - $this->betterNodeFinder = $betterNodeFinder; + $this->reflectionResolver = $reflectionResolver; + $this->classLikeAstResolver = $classLikeAstResolver; } public function supports(Expr $expr) : bool { @@ -49,8 +57,8 @@ final class LocalPropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterf } public function isRead(Expr $expr) : bool { - $class = $this->betterNodeFinder->findParentType($expr, Class_::class); - if (!$class instanceof Class_) { + $classReflection = $this->reflectionResolver->resolveClassReflection($expr); + if (!$classReflection instanceof ClassReflection || !$classReflection->isClass()) { // assume worse to keep node protected return \true; } @@ -59,6 +67,8 @@ final class LocalPropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterf // assume worse to keep node protected return \true; } + /** @var Class_ $class */ + $class = $this->classLikeAstResolver->resolveClassFromClassReflection($classReflection); $propertyFetches = $this->propertyFetchFinder->findLocalPropertyFetchesByName($class, $propertyName); foreach ($propertyFetches as $propertyFetch) { if ($this->justReadExprAnalyzer->isReadContext($propertyFetch)) { diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index aa2da2977be..b80ff650366 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 = '8550c092de01d1167d95922a77490c282f3154d5'; + public const PACKAGE_VERSION = '5f976fa8c3eccf209e17e16d36fb6eb68c782ab4'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-06-18 02:33:10'; + public const RELEASE_DATE = '2023-06-18 03:12:56'; /** * @var int */ diff --git a/src/PhpParser/NodeFinder/PropertyFetchFinder.php b/src/PhpParser/NodeFinder/PropertyFetchFinder.php index 44844eb3576..1df83e9978d 100644 --- a/src/PhpParser/NodeFinder/PropertyFetchFinder.php +++ b/src/PhpParser/NodeFinder/PropertyFetchFinder.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace Rector\Core\PhpParser\NodeFinder; +use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; @@ -84,14 +85,16 @@ final class PropertyFetchFinder */ public function findLocalPropertyFetchesByName(Class_ $class, string $paramName) : array { - /** @var PropertyFetch[]|StaticPropertyFetch[] $propertyFetches */ - $propertyFetches = $this->betterNodeFinder->findInstancesOf($class, [PropertyFetch::class, StaticPropertyFetch::class]); - $foundPropertyFetches = []; - foreach ($propertyFetches as $propertyFetch) { - if ($this->propertyFetchAnalyzer->isLocalPropertyFetchName($propertyFetch, $paramName)) { - $foundPropertyFetches[] = $propertyFetch; + /** @var PropertyFetch[]|StaticPropertyFetch[] $foundPropertyFetches */ + $foundPropertyFetches = $this->betterNodeFinder->find($class->getMethods(), function (Node $subNode) use($paramName) : bool { + if ($subNode instanceof PropertyFetch) { + return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName); } - } + if ($subNode instanceof StaticPropertyFetch) { + return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName); + } + return \false; + }); return $foundPropertyFetches; } /** diff --git a/vendor/autoload.php b/vendor/autoload.php index 026ebb5a96a..9c65c512f10 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 ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7::getLoader(); +return ComposerAutoloaderInit4a8167255d24e2d319fa9c0d2dfb312f::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index b2c8648a6ea..eb8eebf1244 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7 +class ComposerAutoloaderInit4a8167255d24e2d319fa9c0d2dfb312f { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit4a8167255d24e2d319fa9c0d2dfb312f', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit4a8167255d24e2d319fa9c0d2dfb312f', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$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 12f36c9601e..0cd55163fc5 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7 +class ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3094,9 +3094,9 @@ class ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$classMap; }, null, ClassLoader::class); }