reflectionProvider = $reflectionProvider;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->nodeNameResolver = $nodeNameResolver;
$this->classAnalyzer = $classAnalyzer;
$this->methodReflectionResolver = $methodReflectionResolver;
}
/**
* @api
*/
public function resolveClassAndAnonymousClass(ClassLike $classLike) : ClassReflection
{
if ($classLike instanceof Class_ && $this->classAnalyzer->isAnonymousClass($classLike)) {
$classLikeScope = $classLike->getAttribute(AttributeKey::SCOPE);
if (!$classLikeScope instanceof Scope) {
throw new ShouldNotHappenException();
}
return $this->reflectionProvider->getAnonymousClassReflection($classLike, $classLikeScope);
}
$className = (string) $this->nodeNameResolver->getName($classLike);
return $this->reflectionProvider->getClass($className);
}
public function resolveClassReflection(?Node $node) : ?ClassReflection
{
if (!$node instanceof Node) {
return null;
}
$scope = $node->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
return null;
}
return $scope->getClassReflection();
}
/**
* @param \PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\NullsafeMethodCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\PropertyFetch|\PhpParser\Node\Expr\StaticPropertyFetch $node
*/
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) {
$propertyName = (string) $this->nodeNameResolver->getName($node->name);
if (!$classReflection->hasNativeProperty($propertyName)) {
return null;
}
$property = $classReflection->getNativeProperty($propertyName);
if ($property->isPrivate()) {
return $classReflection;
}
if ($this->reflectionProvider->hasClass($property->getDeclaringClass()->getName())) {
return $this->reflectionProvider->getClass($property->getDeclaringClass()->getName());
}
return $classReflection;
}
$methodName = (string) $this->nodeNameResolver->getName($node->name);
if (!$classReflection->hasNativeMethod($methodName)) {
return null;
}
$extendedMethodReflection = $classReflection->getNativeMethod($methodName);
if ($extendedMethodReflection->isPrivate()) {
return $classReflection;
}
if ($this->reflectionProvider->hasClass($extendedMethodReflection->getDeclaringClass()->getName())) {
return $this->reflectionProvider->getClass($extendedMethodReflection->getDeclaringClass()->getName());
}
return $classReflection;
}
/**
* @param class-string $className
*/
public function resolveMethodReflection(string $className, string $methodName, ?Scope $scope) : ?MethodReflection
{
return $this->methodReflectionResolver->resolveMethodReflection($className, $methodName, $scope);
}
public function resolveMethodReflectionFromStaticCall(StaticCall $staticCall) : ?MethodReflection
{
$objectType = $this->nodeTypeResolver->getType($staticCall->class);
if ($objectType instanceof ShortenedObjectType) {
/** @var array