public function enterNode(Node $node)
{
$this->repairComments($node);
if ($node instanceof Node\Stmt\ClassLike) {
$this->classStack[] = $node->namespacedName->toString();
if (!empty($node->extends) && !is_array($node->extends)) {
// Should always be fully qualified
$this->parentStack[] = $node->extends->toString();
} else {
$this->parentStack[] = '';
}
}
$this->repairComments($node);
if ($node instanceof Node\Stmt\Function_) {
$this->functionStack[] = $node->namespacedName->toString();
} elseif ($node instanceof Node\Stmt\ClassMethod) {
$this->methodStack[] = end($this->classStack) . '::' . $node->name;
} elseif ($node instanceof Node\Name) {
switch (strtolower($node->toString())) {
case 'self':
if (!empty($this->classStack)) {
return new Node\Name\FullyQualified(end($this->classStack), $node->getAttributes());
}
break;
case 'parent':
if (!empty($this->parentStack) && '' !== end($this->parentStack)) {
return new Node\Name\FullyQualified(end($this->parentStack), $node->getAttributes());
}
}
} elseif ($node instanceof Node\Scalar\MagicConst\Class_) {
if (!empty($this->classStack)) {
return new Node\Scalar\String_(end($this->classStack), $node->getAttributes());
}
} elseif ($node instanceof Node\Scalar\MagicConst\Trait_) {
// Traits can't nest, so this works...
if (!empty($this->classStack)) {
return new Node\Scalar\String_(end($this->classStack), $node->getAttributes());
}
} elseif ($node instanceof Node\Scalar\MagicConst\Namespace_) {
if (!empty($this->classStack)) {
return new Node\Scalar\String_($this->stripClass(end($this->classStack)), $node->getAttributes());
}
} elseif ($node instanceof Node\Scalar\MagicConst\Function_) {
if (!empty($this->functionStack)) {
return new Node\Scalar\String_(end($this->functionStack), $node->getAttributes());
}
} elseif ($node instanceof Node\Scalar\MagicConst\Method) {
if (!empty($this->methodStack)) {
return new Node\Scalar\String_(end($this->methodStack), $node->getAttributes());
}
} elseif ($node instanceof Node\Scalar\MagicConst\Line) {
return new Node\Scalar\LNumber($node->getLine(), $node->getAttributes());
}
}