From ab1ff8301ff4b955b7149e1409e868fbc19951a9 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 17 Jun 2023 19:21:37 +0000 Subject: [PATCH] Updated Rector to commit 8585ff77542ad3ff7cd55226e23378ee866865aa https://github.com/rectorphp/rector-src/commit/8585ff77542ad3ff7cd55226e23378ee866865aa [NodeTypeResolver] Remove parent lookup on ArrayTypeAnalyzer (#4261) --- .../TypeAnalyzer/ArrayTypeAnalyzer.php | 29 +++++++++++-------- src/Application/VersionResolver.php | 4 +-- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 10 +++---- vendor/composer/autoload_static.php | 8 ++--- 5 files changed, 29 insertions(+), 24 deletions(-) diff --git a/packages/NodeTypeResolver/TypeAnalyzer/ArrayTypeAnalyzer.php b/packages/NodeTypeResolver/TypeAnalyzer/ArrayTypeAnalyzer.php index 0a32cb937ce..ef2f3a2218c 100644 --- a/packages/NodeTypeResolver/TypeAnalyzer/ArrayTypeAnalyzer.php +++ b/packages/NodeTypeResolver/TypeAnalyzer/ArrayTypeAnalyzer.php @@ -10,6 +10,7 @@ use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Property; use PHPStan\PhpDocParser\Ast\Type\ArrayShapeNode; +use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\Php\PhpPropertyReflection; use PHPStan\Type\Accessory\HasOffsetType; use PHPStan\Type\Accessory\NonEmptyArrayType; @@ -20,7 +21,7 @@ use PHPStan\Type\MixedType; use PHPStan\Type\Type; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; -use Rector\Core\PhpParser\Node\BetterNodeFinder; +use Rector\Core\PhpParser\ClassLikeAstResolver; use Rector\Core\Reflection\ReflectionResolver; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\NodeTypeResolver; @@ -36,11 +37,6 @@ final class ArrayTypeAnalyzer * @var \Rector\NodeTypeResolver\NodeTypeResolver */ private $nodeTypeResolver; - /** - * @readonly - * @var \Rector\Core\PhpParser\Node\BetterNodeFinder - */ - private $betterNodeFinder; /** * @readonly * @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory @@ -51,13 +47,18 @@ final class ArrayTypeAnalyzer * @var \Rector\Core\Reflection\ReflectionResolver */ private $reflectionResolver; - public function __construct(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, BetterNodeFinder $betterNodeFinder, PhpDocInfoFactory $phpDocInfoFactory, ReflectionResolver $reflectionResolver) + /** + * @readonly + * @var \Rector\Core\PhpParser\ClassLikeAstResolver + */ + private $classLikeAstResolver; + public function __construct(NodeNameResolver $nodeNameResolver, NodeTypeResolver $nodeTypeResolver, PhpDocInfoFactory $phpDocInfoFactory, ReflectionResolver $reflectionResolver, ClassLikeAstResolver $classLikeAstResolver) { $this->nodeNameResolver = $nodeNameResolver; $this->nodeTypeResolver = $nodeTypeResolver; - $this->betterNodeFinder = $betterNodeFinder; $this->phpDocInfoFactory = $phpDocInfoFactory; $this->reflectionResolver = $reflectionResolver; + $this->classLikeAstResolver = $classLikeAstResolver; } public function isArrayType(Expr $expr) : bool { @@ -108,14 +109,16 @@ final class ArrayTypeAnalyzer if (!$expr instanceof PropertyFetch && !$expr instanceof StaticPropertyFetch) { return \false; } - $classLike = $this->betterNodeFinder->findParentType($expr, ClassLike::class); - if (!$classLike instanceof ClassLike) { + $classReflection = $this->reflectionResolver->resolveClassReflection($expr); + if (!$classReflection instanceof ClassReflection) { return \false; } $propertyName = $this->nodeNameResolver->getName($expr->name); if ($propertyName === null) { return \false; } + /** @var ClassLike $classLike */ + $classLike = $this->classLikeAstResolver->resolveClassFromClassReflection($classReflection); $property = $classLike->getProperty($propertyName); if (!$property instanceof Property) { return \false; @@ -139,10 +142,12 @@ final class ArrayTypeAnalyzer if (!$expr instanceof PropertyFetch && !$expr instanceof StaticPropertyFetch) { return \false; } - $classLike = $this->betterNodeFinder->findParentType($expr, ClassLike::class); - if (!$classLike instanceof ClassLike) { + $classReflection = $this->reflectionResolver->resolveClassReflection($expr); + if (!$classReflection instanceof ClassReflection) { return \false; } + /** @var ClassLike $classLike */ + $classLike = $this->classLikeAstResolver->resolveClassFromClassReflection($classReflection); $propertyName = $this->nodeNameResolver->getName($expr->name); if ($propertyName === null) { return \false; diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 75660b10169..e6db31a4ce3 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 = 'ad65e0445c0a68393d7031067f095ea9f8b1cbde'; + public const PACKAGE_VERSION = '8585ff77542ad3ff7cd55226e23378ee866865aa'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-06-18 01:20:01'; + public const RELEASE_DATE = '2023-06-18 02:16:03'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 351acc49421..eb0ae29a520 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 ComposerAutoloaderInitacb289715da70e548cc7249242948952::getLoader(); +return ComposerAutoloaderInit45ad86eb8329557aaaa52a427f6e2496::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 2535c585382..370e5747564 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitacb289715da70e548cc7249242948952 +class ComposerAutoloaderInit45ad86eb8329557aaaa52a427f6e2496 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInitacb289715da70e548cc7249242948952 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitacb289715da70e548cc7249242948952', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit45ad86eb8329557aaaa52a427f6e2496', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitacb289715da70e548cc7249242948952', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit45ad86eb8329557aaaa52a427f6e2496', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitacb289715da70e548cc7249242948952::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit45ad86eb8329557aaaa52a427f6e2496::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInitacb289715da70e548cc7249242948952::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit45ad86eb8329557aaaa52a427f6e2496::$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 bd99c2b86e6..f8387520271 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitacb289715da70e548cc7249242948952 +class ComposerStaticInit45ad86eb8329557aaaa52a427f6e2496 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3094,9 +3094,9 @@ class ComposerStaticInitacb289715da70e548cc7249242948952 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitacb289715da70e548cc7249242948952::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitacb289715da70e548cc7249242948952::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitacb289715da70e548cc7249242948952::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit45ad86eb8329557aaaa52a427f6e2496::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit45ad86eb8329557aaaa52a427f6e2496::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit45ad86eb8329557aaaa52a427f6e2496::$classMap; }, null, ClassLoader::class); }