mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-26 04:32:36 +01:00
add NodeTypeResolver to more services
This commit is contained in:
parent
6f3dd6a17a
commit
61d2cb26fd
@ -6,12 +6,23 @@ use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
|
||||
/**
|
||||
* Checks "public function methodCall()"
|
||||
*/
|
||||
final class ClassMethodAnalyzer
|
||||
{
|
||||
/**
|
||||
* @var NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
|
||||
public function __construct(NodeTypeResolver $nodeTypeResolver)
|
||||
{
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $methods
|
||||
*/
|
||||
@ -32,7 +43,7 @@ final class ClassMethodAnalyzer
|
||||
}
|
||||
|
||||
$classNode = $node->getAttribute(Attribute::CLASS_NODE);
|
||||
$nodeTypes = (array) $classNode->getAttribute(Attribute::TYPES);
|
||||
$nodeTypes = $this->nodeTypeResolver->resolve($classNode);
|
||||
|
||||
return in_array($type, $nodeTypes, true);
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ use PhpParser\Node\Expr\Isset_;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Unset_;
|
||||
use Rector\Node\Attribute;
|
||||
use Rector\Node\MethodCallNodeFactory;
|
||||
use Rector\NodeTypeResolver\NodeTypeResolver;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
/**
|
||||
@ -40,15 +40,24 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
|
||||
*/
|
||||
private $methodCallNodeFactory;
|
||||
|
||||
/**
|
||||
* @var NodeTypeResolver
|
||||
*/
|
||||
private $nodeTypeResolver;
|
||||
|
||||
/**
|
||||
* Type to method call()
|
||||
*
|
||||
* @param string[][][] $typeToMethodCalls
|
||||
*/
|
||||
public function __construct(array $typeToMethodCalls, MethodCallNodeFactory $methodCallNodeFactory)
|
||||
{
|
||||
public function __construct(
|
||||
array $typeToMethodCalls,
|
||||
MethodCallNodeFactory $methodCallNodeFactory,
|
||||
NodeTypeResolver $nodeTypeResolver
|
||||
) {
|
||||
$this->typeToMethodCalls = $typeToMethodCalls;
|
||||
$this->methodCallNodeFactory = $methodCallNodeFactory;
|
||||
$this->nodeTypeResolver = $nodeTypeResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -126,7 +135,7 @@ final class UnsetAndIssetToMethodCallRector extends AbstractRector
|
||||
|
||||
private function matchArrayDimFetch(ArrayDimFetch $arrayDimFetchNode): bool
|
||||
{
|
||||
$variableNodeTypes = $arrayDimFetchNode->var->getAttribute(Attribute::TYPES);
|
||||
$variableNodeTypes = $this->nodeTypeResolver->resolve($arrayDimFetchNode->var);
|
||||
|
||||
foreach ($this->typeToMethodCalls as $type => $transformation) {
|
||||
if (in_array($type, $variableNodeTypes, true)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user