remove MethodCallCallerTypeResolver, not needed anymore

This commit is contained in:
TomasVotruba 2018-01-08 01:26:07 +01:00
parent 4e929d579d
commit 785a010b7d

View File

@ -1,77 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\NodeTypeResolver\PerNodeCallerTypeResolver;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use Rector\BetterReflection\Reflector\MethodReflector;
use Rector\NodeTypeResolver\Contract\PerNodeCallerTypeResolver\PerNodeCallerTypeResolverInterface;
use Rector\NodeTypeResolver\NodeTypeResolver;
/**
* This will tell the type of Node, which is calling this method
*
* E.g.:
* - {$this}->callMe()
* - $this->{getThis()}->callMe()
* - {new John}->callMe()
*/
final class MethodCallCallerTypeResolver implements PerNodeCallerTypeResolverInterface
{
/**
* @var MethodReflector
*/
private $methodReflector;
/**
* @var NodeTypeResolver
*/
private $nodeTypeResolver;
public function __construct(MethodReflector $methodReflector, NodeTypeResolver $nodeTypeResolver)
{
$this->methodReflector = $methodReflector;
$this->nodeTypeResolver = $nodeTypeResolver;
}
/**
* @return string[]
*/
public function getNodeClasses(): array
{
return [MethodCall::class];
}
/**
* Returns on magic method calls, void type, scalar types and array types.
*
* @param MethodCall $methodCallNode
* @return string[]
*/
public function resolve(Node $methodCallNode): array
{
if ($methodCallNode->var instanceof MethodCall) {
$parentReturnTypes = $this->resolve($methodCallNode->var);
/** @var Identifier $identifierNode */
$identifierNode = $methodCallNode->var->name;
$methodName = $identifierNode->toString();
$returnTypes = $this->methodReflector->resolveReturnTypesForTypesAndMethod($parentReturnTypes, $methodName);
if ($returnTypes) {
return array_unique($returnTypes);
}
}
if ($methodCallNode->var instanceof Variable || $methodCallNode->var instanceof PropertyFetch) {
return $this->nodeTypeResolver->resolve($methodCallNode->var);
}
// unable to determine
return [];
}
}