mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
503a6059f8
a8922f7431
skip temporarily match + throws downagrade in symfony/console, very unlikely to run
54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\DeadCode\NodeAnalyzer;
|
|
|
|
use PhpParser\Node\Expr\MethodCall;
|
|
use PhpParser\Node\Expr\StaticCall;
|
|
use PhpParser\Node\Identifier;
|
|
use PHPStan\Type\TypeWithClassName;
|
|
use Rector\NodeNameResolver\NodeNameResolver;
|
|
use Rector\NodeTypeResolver\NodeTypeResolver;
|
|
final class CallCollectionAnalyzer
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\NodeTypeResolver\NodeTypeResolver
|
|
*/
|
|
private $nodeTypeResolver;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\NodeNameResolver\NodeNameResolver
|
|
*/
|
|
private $nodeNameResolver;
|
|
public function __construct(NodeTypeResolver $nodeTypeResolver, NodeNameResolver $nodeNameResolver)
|
|
{
|
|
$this->nodeTypeResolver = $nodeTypeResolver;
|
|
$this->nodeNameResolver = $nodeNameResolver;
|
|
}
|
|
/**
|
|
* @param StaticCall[]|MethodCall[] $calls
|
|
*/
|
|
public function isExists(array $calls, string $classMethodName, string $className) : bool
|
|
{
|
|
foreach ($calls as $call) {
|
|
$callerRoot = $call instanceof StaticCall ? $call->class : $call->var;
|
|
$callerType = $this->nodeTypeResolver->getType($callerRoot);
|
|
if (!$callerType instanceof TypeWithClassName) {
|
|
continue;
|
|
}
|
|
if ($callerType->getClassName() !== $className) {
|
|
continue;
|
|
}
|
|
if (!$call->name instanceof Identifier) {
|
|
return \true;
|
|
}
|
|
// the method is used
|
|
if ($this->nodeNameResolver->isName($call->name, $classMethodName)) {
|
|
return \true;
|
|
}
|
|
}
|
|
return \false;
|
|
}
|
|
}
|