mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-25 20:23:49 +01:00
merge MethodResolver to ClassResolver
This commit is contained in:
parent
7642500bf3
commit
8f1379483c
@ -3,9 +3,13 @@
|
||||
namespace Rector\NodeTypeResolver\NodeVisitor;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\NodeVisitorAbstract;
|
||||
use Rector\Node\Attribute;
|
||||
|
||||
@ -14,8 +18,11 @@ use Rector\Node\Attribute;
|
||||
* - 'className' with current class name
|
||||
* - 'classNode' with current class node
|
||||
* - 'parentClassName' with current class node
|
||||
* - 'methodName' with current method name
|
||||
* - 'methodNode' with current method node
|
||||
* - 'methodCall' with current method call
|
||||
*/
|
||||
final class ClassResolver extends NodeVisitorAbstract
|
||||
final class ClassAndMethodResolver extends NodeVisitorAbstract
|
||||
{
|
||||
/**
|
||||
* @var ClassLike|null
|
||||
@ -27,6 +34,22 @@ final class ClassResolver extends NodeVisitorAbstract
|
||||
*/
|
||||
private $className;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $methodName;
|
||||
|
||||
/**
|
||||
* @var ClassMethod|null
|
||||
*/
|
||||
private $methodNode;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
private $methodCall;
|
||||
|
||||
|
||||
/**
|
||||
* @param Node[] $nodes
|
||||
*/
|
||||
@ -34,6 +57,9 @@ final class ClassResolver extends NodeVisitorAbstract
|
||||
{
|
||||
$this->classNode = null;
|
||||
$this->className = null;
|
||||
$this->methodName = null;
|
||||
$this->methodNode = null;
|
||||
$this->methodCall = null;
|
||||
}
|
||||
|
||||
public function enterNode(Node $node): void
|
||||
@ -53,6 +79,30 @@ final class ClassResolver extends NodeVisitorAbstract
|
||||
if ($this->classNode instanceof Class_) {
|
||||
$this->setParentClassName($this->classNode, $node);
|
||||
}
|
||||
|
||||
if ($node instanceof ClassMethod) {
|
||||
$this->methodNode = $node;
|
||||
|
||||
/** @var Identifier $identifierNode */
|
||||
$identifierNode = $node->name;
|
||||
|
||||
$this->methodName = $identifierNode->toString();
|
||||
}
|
||||
|
||||
if ($node instanceof MethodCall && $node->name instanceof Identifier) {
|
||||
$this->methodCall = $node->name->toString();
|
||||
}
|
||||
|
||||
$node->setAttribute(Attribute::METHOD_NAME, $this->methodName);
|
||||
$node->setAttribute(Attribute::METHOD_NODE, $this->methodNode);
|
||||
$node->setAttribute(Attribute::METHOD_CALL, $this->methodCall);
|
||||
}
|
||||
|
||||
public function leaveNode(Node $node): void
|
||||
{
|
||||
if ($node instanceof Expression) {
|
||||
$this->methodCall = null;
|
||||
}
|
||||
}
|
||||
|
||||
private function setParentClassName(Class_ $classNode, Node $node): void
|
||||
|
Loading…
x
Reference in New Issue
Block a user