mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
cdc3b7adef
f451b0b8e1
[PHP 8.0] Bump to promoted properties (#4)
53 lines
2.1 KiB
PHP
53 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\Defluent\Reflection;
|
|
|
|
use PhpParser\Node\Expr\MethodCall;
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use PHPStan\Reflection\ReflectionProvider;
|
|
use PHPStan\Type\TypeWithClassName;
|
|
use Rector\Core\Reflection\FunctionLikeReflectionParser;
|
|
use Rector\NodeNameResolver\NodeNameResolver;
|
|
use Rector\NodeTypeResolver\NodeTypeResolver;
|
|
final class MethodCallToClassMethodParser
|
|
{
|
|
/**
|
|
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
|
*/
|
|
private $nodeTypeResolver;
|
|
/**
|
|
* @var \Rector\NodeNameResolver\NodeNameResolver
|
|
*/
|
|
private $nodeNameResolver;
|
|
/**
|
|
* @var \PHPStan\Reflection\ReflectionProvider
|
|
*/
|
|
private $reflectionProvider;
|
|
/**
|
|
* @var \Rector\Core\Reflection\FunctionLikeReflectionParser
|
|
*/
|
|
private $functionLikeReflectionParser;
|
|
public function __construct(\Rector\NodeTypeResolver\NodeTypeResolver $nodeTypeResolver, \Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \PHPStan\Reflection\ReflectionProvider $reflectionProvider, \Rector\Core\Reflection\FunctionLikeReflectionParser $functionLikeReflectionParser)
|
|
{
|
|
$this->nodeTypeResolver = $nodeTypeResolver;
|
|
$this->nodeNameResolver = $nodeNameResolver;
|
|
$this->reflectionProvider = $reflectionProvider;
|
|
$this->functionLikeReflectionParser = $functionLikeReflectionParser;
|
|
}
|
|
public function parseMethodCall(\PhpParser\Node\Expr\MethodCall $methodCall) : ?\PhpParser\Node\Stmt\ClassMethod
|
|
{
|
|
$callerStaticType = $this->nodeTypeResolver->getStaticType($methodCall->var);
|
|
if (!$callerStaticType instanceof \PHPStan\Type\TypeWithClassName) {
|
|
return null;
|
|
}
|
|
$callerClassReflection = $this->reflectionProvider->getClass($callerStaticType->getClassName());
|
|
$methodName = $this->nodeNameResolver->getName($methodCall->name);
|
|
if ($methodName === null) {
|
|
return null;
|
|
}
|
|
$methodReflection = $callerClassReflection->getNativeMethod($methodName);
|
|
return $this->functionLikeReflectionParser->parseMethodReflection($methodReflection);
|
|
}
|
|
}
|