mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
Updated Rector to commit 1d262193e2c28acd5e61733de4a067e30eb51936
1d262193e2
[NodeTypeResolver] Remove findParentType() on NameTypeResolver (#4199)
This commit is contained in:
parent
4bac0a1b1b
commit
17b9256239
@ -6,18 +6,16 @@ namespace Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
use PHPStan\Type\ArrayType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ObjectType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
use Rector\Core\Reflection\ReflectionResolver;
|
||||
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
|
||||
use RectorPrefix202306\Symfony\Contracts\Service\Attribute\Required;
|
||||
/**
|
||||
* @see \Rector\Tests\NodeTypeResolver\PerNodeTypeResolver\NameTypeResolver\NameTypeResolverTest
|
||||
*
|
||||
@ -26,25 +24,15 @@ use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
|
||||
final class NameTypeResolver implements NodeTypeResolverInterface
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
* @var \Rector\Core\Reflection\ReflectionResolver
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
private $reflectionResolver;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
|
||||
* @required
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\NodeNameResolver\NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
public function __construct(ReflectionProvider $reflectionProvider, BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver)
|
||||
public function autowire(ReflectionResolver $reflectionResolver) : void
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
$this->reflectionResolver = $reflectionResolver;
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
@ -72,18 +60,13 @@ final class NameTypeResolver implements NodeTypeResolverInterface
|
||||
*/
|
||||
private function resolveParent(Name $name)
|
||||
{
|
||||
$class = $this->betterNodeFinder->findParentType($name, Class_::class);
|
||||
if (!$class instanceof Class_) {
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($name);
|
||||
if (!$classReflection instanceof ClassReflection || !$classReflection->isClass()) {
|
||||
return new MixedType();
|
||||
}
|
||||
$className = $this->nodeNameResolver->getName($class);
|
||||
if (!\is_string($className)) {
|
||||
if ($classReflection->isAnonymous()) {
|
||||
return new MixedType();
|
||||
}
|
||||
if (!$this->reflectionProvider->hasClass($className)) {
|
||||
return new MixedType();
|
||||
}
|
||||
$classReflection = $this->reflectionProvider->getClass($className);
|
||||
$parentClassObjectTypes = [];
|
||||
foreach ($classReflection->getParents() as $parentClassReflection) {
|
||||
$parentClassObjectTypes[] = new ObjectType($parentClassReflection->getName());
|
||||
@ -100,11 +83,11 @@ final class NameTypeResolver implements NodeTypeResolverInterface
|
||||
{
|
||||
$nameValue = $name->toString();
|
||||
if (\in_array($nameValue, [ObjectReference::SELF, ObjectReference::STATIC, 'this'], \true)) {
|
||||
$classLike = $this->betterNodeFinder->findParentType($name, ClassLike::class);
|
||||
if (!$classLike instanceof ClassLike) {
|
||||
$classReflection = $this->reflectionResolver->resolveClassReflection($name);
|
||||
if (!$classReflection instanceof ClassReflection || $classReflection->isAnonymous()) {
|
||||
return $name->toString();
|
||||
}
|
||||
return (string) $this->nodeNameResolver->getName($classLike);
|
||||
return $classReflection->getName();
|
||||
}
|
||||
return $nameValue;
|
||||
}
|
||||
|
@ -13,7 +13,15 @@ use PhpParser\Node\Expr\AssignOp;
|
||||
use PhpParser\Node\Expr\BinaryOp;
|
||||
use PhpParser\Node\Expr\CallLike;
|
||||
use PhpParser\Node\Expr\Cast;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Expr\ConstFetch;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\New_;
|
||||
use PhpParser\Node\Expr\NullsafeMethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\StaticPropertyFetch;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Identifier;
|
||||
@ -213,6 +221,24 @@ final class PHPStanNodeScopeResolver
|
||||
$type->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
if ($node instanceof StaticPropertyFetch) {
|
||||
$node->class->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$node->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof PropertyFetch) {
|
||||
$node->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$node->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof CallLike) {
|
||||
$this->processCallike($node, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof ConstFetch) {
|
||||
$node->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof ClassConstFetch) {
|
||||
$node->class->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$node->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($node instanceof Trait_) {
|
||||
$traitName = $this->resolveClassName($node);
|
||||
$traitClassReflection = $this->reflectionProvider->getClass($traitName);
|
||||
@ -245,6 +271,39 @@ final class PHPStanNodeScopeResolver
|
||||
};
|
||||
return $this->processNodesWithDependentFiles($filePath, $stmts, $scope, $nodeCallback);
|
||||
}
|
||||
private function processCallike(CallLike $callLike, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
$this->processArgsForCallike($callLike, $mutatingScope);
|
||||
if ($callLike instanceof StaticCall) {
|
||||
$callLike->class->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$callLike->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($callLike instanceof MethodCall) {
|
||||
$callLike->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$callLike->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($callLike instanceof FuncCall) {
|
||||
$callLike->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($callLike instanceof New_ && !$callLike->class instanceof Class_) {
|
||||
$callLike->class->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
if ($callLike instanceof NullsafeMethodCall) {
|
||||
$callLike->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$callLike->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
private function processArgsForCallike(Expr $expr, MutatingScope $mutatingScope) : void
|
||||
{
|
||||
if (!$expr instanceof CallLike) {
|
||||
return;
|
||||
}
|
||||
if (!$expr->isFirstClassCallable()) {
|
||||
foreach ($expr->getArgs() as $arg) {
|
||||
$arg->value->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\Assign|\PhpParser\Node\Expr\AssignOp $assign
|
||||
*/
|
||||
@ -256,11 +315,7 @@ final class PHPStanNodeScopeResolver
|
||||
}
|
||||
$expr = $assign;
|
||||
while ($expr instanceof Assign || $expr instanceof AssignOp) {
|
||||
if ($expr->expr instanceof CallLike && !$expr->expr->isFirstClassCallable()) {
|
||||
foreach ($expr->expr->getArgs() as $arg) {
|
||||
$arg->value->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
}
|
||||
}
|
||||
$this->processArgsForCallike($expr->expr, $mutatingScope);
|
||||
// decorate value as well
|
||||
$expr->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
|
||||
$expr = $expr->expr;
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '8263d9097dd362abd5f9f3ffa6aa560b2abffa8d';
|
||||
public const PACKAGE_VERSION = '1d262193e2c28acd5e61733de4a067e30eb51936';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-06-17 11:50:29';
|
||||
public const RELEASE_DATE = '2023-06-17 13:16:44';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitf2ece9244f054090d0f0593eeeec3f90::getLoader();
|
||||
return ComposerAutoloaderInit3125a7387f933c54b227753c08ffa384::getLoader();
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitf2ece9244f054090d0f0593eeeec3f90
|
||||
class ComposerAutoloaderInit3125a7387f933c54b227753c08ffa384
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInitf2ece9244f054090d0f0593eeeec3f90
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitf2ece9244f054090d0f0593eeeec3f90', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3125a7387f933c54b227753c08ffa384', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitf2ece9244f054090d0f0593eeeec3f90', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3125a7387f933c54b227753c08ffa384', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitf2ece9244f054090d0f0593eeeec3f90::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3125a7387f933c54b227753c08ffa384::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitf2ece9244f054090d0f0593eeeec3f90::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit3125a7387f933c54b227753c08ffa384::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitf2ece9244f054090d0f0593eeeec3f90
|
||||
class ComposerStaticInit3125a7387f933c54b227753c08ffa384
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -3094,9 +3094,9 @@ class ComposerStaticInitf2ece9244f054090d0f0593eeeec3f90
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitf2ece9244f054090d0f0593eeeec3f90::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitf2ece9244f054090d0f0593eeeec3f90::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitf2ece9244f054090d0f0593eeeec3f90::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3125a7387f933c54b227753c08ffa384::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3125a7387f933c54b227753c08ffa384::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3125a7387f933c54b227753c08ffa384::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user