Updated Rector to commit 5f976fa8c3eccf209e17e16d36fb6eb68c782ab4

5f976fa8c3 [ReadWrite] Remove parent lookup on LocalPropertyFetchReadNodeAnalyzer (#4263)
This commit is contained in:
Tomas Votruba 2023-06-17 20:18:18 +00:00
parent a0d8cc6508
commit c363d3ea16
6 changed files with 39 additions and 26 deletions

View File

@ -7,8 +7,10 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Stmt\Class_; 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\PhpParser\NodeFinder\PropertyFetchFinder;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeNameResolver\NodeNameResolver;
use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface; use Rector\ReadWrite\Contract\ReadNodeAnalyzerInterface;
/** /**
@ -33,15 +35,21 @@ final class LocalPropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterf
private $nodeNameResolver; private $nodeNameResolver;
/** /**
* @readonly * @readonly
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder * @var \Rector\Core\Reflection\ReflectionResolver
*/ */
private $betterNodeFinder; private $reflectionResolver;
public function __construct(\Rector\ReadWrite\ReadNodeAnalyzer\JustReadExprAnalyzer $justReadExprAnalyzer, PropertyFetchFinder $propertyFetchFinder, NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder) /**
* @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->justReadExprAnalyzer = $justReadExprAnalyzer;
$this->propertyFetchFinder = $propertyFetchFinder; $this->propertyFetchFinder = $propertyFetchFinder;
$this->nodeNameResolver = $nodeNameResolver; $this->nodeNameResolver = $nodeNameResolver;
$this->betterNodeFinder = $betterNodeFinder; $this->reflectionResolver = $reflectionResolver;
$this->classLikeAstResolver = $classLikeAstResolver;
} }
public function supports(Expr $expr) : bool public function supports(Expr $expr) : bool
{ {
@ -49,8 +57,8 @@ final class LocalPropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterf
} }
public function isRead(Expr $expr) : bool public function isRead(Expr $expr) : bool
{ {
$class = $this->betterNodeFinder->findParentType($expr, Class_::class); $classReflection = $this->reflectionResolver->resolveClassReflection($expr);
if (!$class instanceof Class_) { if (!$classReflection instanceof ClassReflection || !$classReflection->isClass()) {
// assume worse to keep node protected // assume worse to keep node protected
return \true; return \true;
} }
@ -59,6 +67,8 @@ final class LocalPropertyFetchReadNodeAnalyzer implements ReadNodeAnalyzerInterf
// assume worse to keep node protected // assume worse to keep node protected
return \true; return \true;
} }
/** @var Class_ $class */
$class = $this->classLikeAstResolver->resolveClassFromClassReflection($classReflection);
$propertyFetches = $this->propertyFetchFinder->findLocalPropertyFetchesByName($class, $propertyName); $propertyFetches = $this->propertyFetchFinder->findLocalPropertyFetchesByName($class, $propertyName);
foreach ($propertyFetches as $propertyFetch) { foreach ($propertyFetches as $propertyFetch) {
if ($this->justReadExprAnalyzer->isReadContext($propertyFetch)) { if ($this->justReadExprAnalyzer->isReadContext($propertyFetch)) {

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '8550c092de01d1167d95922a77490c282f3154d5'; public const PACKAGE_VERSION = '5f976fa8c3eccf209e17e16d36fb6eb68c782ab4';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2023-06-18 02:33:10'; public const RELEASE_DATE = '2023-06-18 03:12:56';
/** /**
* @var int * @var int
*/ */

View File

@ -3,6 +3,7 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\Core\PhpParser\NodeFinder; namespace Rector\Core\PhpParser\NodeFinder;
use PhpParser\Node;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
@ -84,14 +85,16 @@ final class PropertyFetchFinder
*/ */
public function findLocalPropertyFetchesByName(Class_ $class, string $paramName) : array public function findLocalPropertyFetchesByName(Class_ $class, string $paramName) : array
{ {
/** @var PropertyFetch[]|StaticPropertyFetch[] $propertyFetches */ /** @var PropertyFetch[]|StaticPropertyFetch[] $foundPropertyFetches */
$propertyFetches = $this->betterNodeFinder->findInstancesOf($class, [PropertyFetch::class, StaticPropertyFetch::class]); $foundPropertyFetches = $this->betterNodeFinder->find($class->getMethods(), function (Node $subNode) use($paramName) : bool {
$foundPropertyFetches = []; if ($subNode instanceof PropertyFetch) {
foreach ($propertyFetches as $propertyFetch) { return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
if ($this->propertyFetchAnalyzer->isLocalPropertyFetchName($propertyFetch, $paramName)) {
$foundPropertyFetches[] = $propertyFetch;
} }
if ($subNode instanceof StaticPropertyFetch) {
return $this->propertyFetchAnalyzer->isLocalPropertyFetchName($subNode, $paramName);
} }
return \false;
});
return $foundPropertyFetches; return $foundPropertyFetches;
} }
/** /**

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7::getLoader(); return ComposerAutoloaderInit4a8167255d24e2d319fa9c0d2dfb312f::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7 class ComposerAutoloaderInit4a8167255d24e2d319fa9c0d2dfb312f
{ {
private static $loader; private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit080ef22abaeaf79a5fc0600bde4b5ee7
return self::$loader; 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__)); 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'; 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->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$files; $filesToLoad = \Composer\Autoload\ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) { $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7 class ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f
{ {
public static $files = array ( public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3094,9 +3094,9 @@ class ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit080ef22abaeaf79a5fc0600bde4b5ee7::$classMap; $loader->classMap = ComposerStaticInit4a8167255d24e2d319fa9c0d2dfb312f::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }