Skip to content

Commit

Permalink
Updated Rector to commit e9b4c647f9f40adc9e1859cd620c3632281e3384
Browse files Browse the repository at this point in the history
rectorphp/rector-src@e9b4c64 [Performance] Remove AstResolver usage on ReflectionResolver (#6144)
  • Loading branch information
TomasVotruba committed Jul 14, 2024
1 parent e21d306 commit a07218c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'a207391d81e8a0e20a9207611c8c9661d851a94e';
public const PACKAGE_VERSION = 'e9b4c647f9f40adc9e1859cd620c3632281e3384';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-07-14 00:30:38';
public const RELEASE_DATE = '2024-07-15 00:03:58';
/**
* @var int
*/
Expand Down
73 changes: 57 additions & 16 deletions src/Reflection/ReflectionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PhpParser\AstResolver;
use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType;
use Rector\ValueObject\MethodName;
final class ReflectionResolver
Expand Down Expand Up @@ -60,19 +59,13 @@ final class ReflectionResolver
* @var \Rector\Reflection\MethodReflectionResolver
*/
private $methodReflectionResolver;
/**
* @readonly
* @var \Rector\PhpParser\AstResolver
*/
private $astResolver;
public function __construct(ReflectionProvider $reflectionProvider, NodeTypeResolver $nodeTypeResolver, NodeNameResolver $nodeNameResolver, ClassAnalyzer $classAnalyzer, \Rector\Reflection\MethodReflectionResolver $methodReflectionResolver, AstResolver $astResolver)
public function __construct(ReflectionProvider $reflectionProvider, NodeTypeResolver $nodeTypeResolver, NodeNameResolver $nodeNameResolver, ClassAnalyzer $classAnalyzer, \Rector\Reflection\MethodReflectionResolver $methodReflectionResolver)
{
$this->reflectionProvider = $reflectionProvider;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->nodeNameResolver = $nodeNameResolver;
$this->classAnalyzer = $classAnalyzer;
$this->methodReflectionResolver = $methodReflectionResolver;
$this->astResolver = $astResolver;
}
/**
* @api
Expand Down Expand Up @@ -105,19 +98,67 @@ public function resolveClassReflection(?Node $node) : ?ClassReflection
*/
public function resolveClassReflectionSourceObject($node) : ?ClassReflection
{
$objectType = $node instanceof StaticCall || $node instanceof StaticPropertyFetch ? $this->nodeTypeResolver->getType($node->class) : $this->nodeTypeResolver->getType($node->var);
if (!$objectType instanceof TypeWithClassName) {
return null;
}
$className = $objectType->getClassName();
if (!$this->reflectionProvider->hasClass($className)) {
return null;
}
$classReflection = $this->reflectionProvider->getClass($className);
if ($node instanceof PropertyFetch || $node instanceof StaticPropertyFetch) {
$objectType = $node instanceof PropertyFetch ? $this->nodeTypeResolver->getType($node->var) : $this->nodeTypeResolver->getType($node->class);
if (!$objectType instanceof TypeWithClassName) {
$propertyName = (string) $this->nodeNameResolver->getName($node->name);
if (!$classReflection->hasNativeProperty($propertyName)) {
return null;
}
$className = $objectType->getClassName();
if (!$this->reflectionProvider->hasClass($className)) {
return null;
$property = $classReflection->getNativeProperty($propertyName);
if ($property->isPrivate()) {
return $classReflection;
}
$nativeReflection = $classReflection->getNativeReflection();
$properties = $nativeReflection->getProperties();
$ancestors = \array_merge($classReflection->getParents(), $classReflection->getInterfaces());
foreach ($properties as $property) {
if ($property->getName() !== $propertyName) {
continue;
}
if ($property->getDeclaringClass()->getName() === $className) {
return $classReflection;
}
foreach ($ancestors as $ancestor) {
if ($ancestor->hasNativeProperty($propertyName)) {
return $ancestor;
}
}
}
return $classReflection;
}
$methodName = (string) $this->nodeNameResolver->getName($node->name);
if (!$classReflection->hasNativeMethod($methodName)) {
return null;
}
$extendedMethodReflection = $classReflection->getNativeMethod($methodName);
if ($extendedMethodReflection->isPrivate()) {
return $classReflection;
}
$nativeReflection = $classReflection->getNativeReflection();
$methods = $nativeReflection->getMethods();
$ancestors = \array_merge($classReflection->getParents(), $classReflection->getInterfaces());
foreach ($methods as $method) {
if ($method->getName() !== $methodName) {
continue;
}
if ($method->getDeclaringClass()->getName() === $className) {
return $classReflection;
}
foreach ($ancestors as $ancestor) {
if ($ancestor->hasNativeMethod($methodName)) {
return $ancestor;
}
}
return $this->reflectionProvider->getClass($className);
}
$classMethod = $this->astResolver->resolveClassMethodFromCall($node);
return $this->resolveClassReflection($classMethod);
return $classReflection;
}
/**
* @param class-string $className
Expand Down

0 comments on commit a07218c

Please sign in to comment.