2020-07-24 13:14:32 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-08-31 02:26:25 +02:00
|
|
|
namespace Rector\Transform\ValueObject;
|
2020-07-24 13:14:32 +02:00
|
|
|
|
|
|
|
use PhpParser\Node\Expr\StaticCall;
|
|
|
|
use PhpParser\Node\Identifier;
|
|
|
|
use PhpParser\Node\Name;
|
|
|
|
|
|
|
|
final class StaticCallToMethodCall
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $staticClass;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $staticMethod;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $classType;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $methodName;
|
|
|
|
|
|
|
|
public function __construct(string $staticClass, string $staticMethod, string $classType, string $methodName)
|
|
|
|
{
|
|
|
|
$this->staticClass = $staticClass;
|
|
|
|
$this->staticMethod = $staticMethod;
|
|
|
|
$this->classType = $classType;
|
|
|
|
$this->methodName = $methodName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClassType(): string
|
|
|
|
{
|
|
|
|
return $this->classType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMethodName(): string
|
|
|
|
{
|
|
|
|
return $this->methodName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function matchStaticCall(StaticCall $staticCall): bool
|
|
|
|
{
|
|
|
|
if (! $staticCall->class instanceof Name) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$staticCallClassName = $staticCall->class->toString();
|
|
|
|
if ($staticCallClassName !== $this->staticClass) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! $staticCall->name instanceof Identifier) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$staticCallMethodName = $staticCall->name->toString();
|
|
|
|
return $staticCallMethodName === $this->staticMethod;
|
|
|
|
}
|
|
|
|
}
|