PhpParser\NodeVisitor\NameResolver::enterNode PHP Method

enterNode() public method

public enterNode ( PhpParser\Node $node )
$node PhpParser\Node
    public function enterNode(Node $node) {
        if ($node instanceof Stmt\Namespace_) {
            $this->resetState($node->name);
        } elseif ($node instanceof Stmt\Use_) {
            foreach ($node->uses as $use) {
                $this->addAlias($use, $node->type, null);
            }
        } elseif ($node instanceof Stmt\GroupUse) {
            foreach ($node->uses as $use) {
                $this->addAlias($use, $node->type, $node->prefix);
            }
        } elseif ($node instanceof Stmt\Class_) {
            if (null !== $node->extends) {
                $node->extends = $this->resolveClassName($node->extends);
            }

            foreach ($node->implements as &$interface) {
                $interface = $this->resolveClassName($interface);
            }

            if (null !== $node->name) {
                $this->addNamespacedName($node);
            }
        } elseif ($node instanceof Stmt\Interface_) {
            foreach ($node->extends as &$interface) {
                $interface = $this->resolveClassName($interface);
            }

            $this->addNamespacedName($node);
        } elseif ($node instanceof Stmt\Trait_) {
            $this->addNamespacedName($node);
        } elseif ($node instanceof Stmt\Function_) {
            $this->addNamespacedName($node);
            $this->resolveSignature($node);
        } elseif ($node instanceof Stmt\ClassMethod
                  || $node instanceof Expr\Closure
        ) {
            $this->resolveSignature($node);
        } elseif ($node instanceof Stmt\Const_) {
            foreach ($node->consts as $const) {
                $this->addNamespacedName($const);
            }
        } elseif ($node instanceof Expr\StaticCall
                  || $node instanceof Expr\StaticPropertyFetch
                  || $node instanceof Expr\ClassConstFetch
                  || $node instanceof Expr\New_
                  || $node instanceof Expr\Instanceof_
        ) {
            if ($node->class instanceof Name) {
                $node->class = $this->resolveClassName($node->class);
            }
        } elseif ($node instanceof Stmt\Catch_) {
            foreach ($node->types as &$type) {
                $type = $this->resolveClassName($type);
            }
        } elseif ($node instanceof Expr\FuncCall) {
            if ($node->name instanceof Name) {
                $node->name = $this->resolveOtherName($node->name, Stmt\Use_::TYPE_FUNCTION);
            }
        } elseif ($node instanceof Expr\ConstFetch) {
            $node->name = $this->resolveOtherName($node->name, Stmt\Use_::TYPE_CONSTANT);
        } elseif ($node instanceof Stmt\TraitUse) {
            foreach ($node->traits as &$trait) {
                $trait = $this->resolveClassName($trait);
            }

            foreach ($node->adaptations as $adaptation) {
                if (null !== $adaptation->trait) {
                    $adaptation->trait = $this->resolveClassName($adaptation->trait);
                }

                if ($adaptation instanceof Stmt\TraitUseAdaptation\Precedence) {
                    foreach ($adaptation->insteadof as &$insteadof) {
                        $insteadof = $this->resolveClassName($insteadof);
                    }
                }
            }
        } elseif ($node instanceof Node\NullableType) {
            if ($node->type instanceof Name) {
                $node->type = $this->resolveClassName($node->type);
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function enterNode(Node $node)
 {
     parent::enterNode($node);
     if ($node instanceof Class_) {
         $this->currentClass = (string) $node->namespacedName;
     }
     if ($node instanceof ClassMethod) {
         $methodName = $this->currentClass . ($node->isStatic() ? '::' : '->') . $node->name;
         $this->currentMethod[] = $methodName;
     }
     if ($node instanceof Function_) {
         $this->currentMethod[] = (string) $node->namespacedName;
     }
     if ($node instanceof FuncCall) {
         if ($this->isTombstoneFunction($node)) {
             $line = $node->getLine();
             $methodName = $this->getCurrentMethodName();
             $params = $this->extractParameters($node);
             $date = isset($params[0]) ? $params[0] : null;
             $author = isset($params[1]) ? $params[1] : null;
             $label = isset($params[2]) ? $params[2] : null;
             $tombstone = new Tombstone($date, $author, $label, $this->file, $line, $methodName);
             $this->tombstoneIndex->addTombstone($tombstone);
         }
     }
 }
All Usage Examples Of PhpParser\NodeVisitor\NameResolver::enterNode