Traverse a node when leaving.
@param  \PhpParser\Node $node Traversing node
@return \PhpParser\Node\Name Updated node
550303
public function leaveNode(Node $node)
    {
        if ($node instanceof Stmt\Class_
            || $node instanceof Stmt\Interface_
            || $node instanceof Stmt\Trait_
        ) {
            if (empty($this->suffix) && !empty($this->namespaceNode)) {
                $node->name = $this->append(new Name($node->name), $this->namespaceNode);
            }
            else {
                $node->name = $node->name . $this->suffix;
            }
        } elseif ($node instanceof Name) {
            if (!$this->cancelNext) {
                return $this->appendSuffix($node);
            }
            $this->cancelNext = false;
        } elseif ($node instanceof Stmt\Use_) {
            $this->isImport = false;
        } elseif ($node instanceof Stmt\GroupUse) {
            $this->groupImport = false;
        }
    }
498841
public function enterNode(Node $node): Node
    {
        if (false === ($node instanceof Const_)) {
            return $node;
        }

        foreach ($node->consts as $constant) {
            /** @var Node\Const_ $constant */
            $resolvedConstantName = $this->nameResolver->resolveName(
                new Name(
                    (string) $constant->name,
                    $node->getAttributes()
                )
            )->getName();

            if (false === $this->whitelist->isSymbolWhitelisted((string) $resolvedConstantName, true)) {
                continue;
            }

            if (count($node->consts) > 1) {
                throw new UnexpectedValueException(
                    'Whitelisting a constant declared in a grouped constant statement (e.g. `const FOO = '
                    .'\'foo\', BAR = \'bar\'; is not supported. Consider breaking it down in multiple constant '
                    .'declaration statements'
                );
            }

            return new Expression(
                new FuncCall(
                    new FullyQualified('define'),
                    [
                        new Arg(
                            new String_((string) $resolvedConstantName)
                        ),
                        new Arg($constant->value),
                    ]
                )
            );
        }

        return $node;
    }
161410
private function getIndex($node) {
    $oidStr = $node->getOID()->__toString();
    if (!isset($this->nodeIndexMap[$oidStr])) {
      $this->nodeIndexMap[$oidStr] = $this->getNextIndex();
    }
    return $this->nodeIndexMap[$oidStr];
  }
1029726
public function enterNode(Node $node)
    {
        if ($node instanceof Stmt\Namespace_) {
            $this->cancelNext = true;
            $this->namespaceNode = $node->name;
        } elseif ($node instanceof Stmt\GroupUse) {
            $this->cancelNext = true;
            $this->groupImport = $node->prefix;
            foreach ($node->uses as $use) {
                $this->importNodes[] = Name::concat($node->prefix, $use->name);
            }
        } elseif ($node instanceof Stmt\Use_) {
            foreach ($node->uses as $use) {
                $this->importNodes[] = $use->name;
            }
        } elseif ($node instanceof Stmt\UseUse) {
            $this->isImport = true;
        } elseif ($node instanceof Expr\FuncCall) {
            $this->cancelNext = true;
        } elseif ($node instanceof Expr\ConstFetch) {
            $this->cancelNext = true;
        } elseif ($node instanceof Expr\StaticCall) {
            $this->cancelNext = true;
        } elseif ($node instanceof Expr\StaticPropertyFetch) {
            $lc = strtolower($node->class->toString());
            if (in_array($lc, ['static', 'self', 'parent'])) {
                $this->cancelNext = true;
            }
        } elseif ($node instanceof Expr\ClassConstFetch) {
            $lc = strtolower($node->class->toString());
            if (in_array($lc, ['static', 'self', 'parent'])) {
                $this->cancelNext = true;
            }
        } elseif ($node instanceof Expr\New_) {
            if ($node->class && $node->class instanceof Name) {
                $lc = strtolower($node->class->toString());
                if (in_array($lc, ['static', 'self', 'parent'])) {
                    $this->cancelNext = true;
                }
            }
        }
    }
1270203
public function transform($node)
    {
        $blocksData = $this->transformBlock($node);
        $documentData = array(
            'id' => $node->getNodeId() . '-' . $node->getLanguage(). '-' . $node->getSiteId(),
            'elementId' => $node->getId(),
            'nodeId' => $node->getNodeId(),
            'siteId' => $node->getSiteId(),
            'language' => $node->getLanguage(),
            'name' => $node->getName(),
            'blocks' => $blocksData
        );

        if (!is_null($node->getUpdatedAt())) {
            $documentData['updatedAt'] = $node->getUpdatedAt()->getTimestamp();
        }

        $document = new Document($documentData['id'], $documentData);

        return $document;
    }
602781
private function getOuterMostArrayNode(Node $node): Node
    {
        $outerMostArrayParent = $node;

        do {
            if ($node instanceof Node\Expr\Array_) {
                $outerMostArrayParent = $node;
            }
        } while ($node = $node->getAttribute(ParentConnectorVisitor::PARENT_KEY));

        return $outerMostArrayParent;
    }
1015322
public function leaveNode(Node $node)
    {
        if (!$node instanceof ClassLikeNode) {
            return null;
        }

        // not in class context
        if ($this->currentClass === null) {
            $this->tempDependencies = new DependencySet();
            return;
        }

        // by now the class should have been parsed so replace the
        // temporary class with the parsed class name

        $this->dependencies = $this->dependencies->addSet(
            $this->currentClass,
            $this->tempDependencies
        );
        $this->tempDependencies = new DependencySet();
        $this->currentClass = null;
    }
1264936
public function leaveNode(Node $node) {
        if ($this->phpClass instanceof PhpClass) {
            if ($node instanceof Class_) {
                if (!empty($node->extends) && count($node->extends->parts) > 0) {
                    $this->phpClass->setExtends(implode('\\', $node->extends->parts));
                }

                if (!empty($node->implements) && is_array($node->implements)) {
                    foreach ($node->implements as $implements) {
                        $this->phpClass->setImplements(implode('\\', $implements->parts));
                    }
                }

                if ($node->type === 0) {
                    $this->phpClass->setClassType(PhpClass::TYPE_CLASS);
                } elseif ($node->type === 16) {
                    $this->phpClass->setClassType(PhpClass::TYPE_ABSTRACT_CLASS);
                } elseif ($node->type === 32) {
                    $this->phpClass->setClassType(PhpClass::TYPE_FINAL_CLASS);
                }

                $this->phpClass->setClass($node->name);
            } elseif ($node instanceof Interface_) {
                if (!empty($node->extends) && is_array($node->extends)) {
                    foreach ($node->extends as $implements) {
                        $this->phpClass->setImplements(implode('\\', $implements->parts));
                    }
                }

                $this->phpClass->setClassType(PhpClass::TYPE_INTERFACE);
                $this->phpClass->setClass($node->name);
            } elseif ($node instanceof Trait_) {
                $this->phpClass->setClassType(PhpClass::TYPE_TRAIT);
                $this->phpClass->setClass($node->name);
            } elseif ($node instanceof Namespace_) {
                $this->phpClass->setNamespace(implode('\\', $node->name->parts));
            } elseif ($node instanceof TraitUse) {
                if (!empty($node->traits) && is_array($node->traits)) {
                    foreach ($node->traits as $trait) {
                        $this->phpClass->setTraits(implode('\\', $trait->parts));
                    }
                }
            }
        }
    }
1271682
public function enterNode(PhpParser\Node $node)
    {
        $attrs = $node->getAttributes();

        if ($cs = $node->getComments()) {
            $new_comments = [];

            foreach ($cs as $c) {
                if ($c instanceof PhpParser\Comment\Doc) {
                    $new_comments[] = new PhpParser\Comment\Doc(
                        $c->getText(),
                        $c->getLine() + $this->line_offset,
                        $c->getFilePos() + $this->file_offset
                    );
                } else {
                    $new_comments[] = new PhpParser\Comment(
                        $c->getText(),
                        $c->getLine() + $this->line_offset,
                        $c->getFilePos() + $this->file_offset
                    );
                }
            }

            $node->setAttribute('comments', $new_comments);
        }

        /** @psalm-suppress MixedOperand */
        $node->setAttribute('startFilePos', $attrs['startFilePos'] + $this->file_offset);
        /** @psalm-suppress MixedOperand */
        $node->setAttribute('endFilePos', $attrs['endFilePos'] + $this->file_offset);
        /** @psalm-suppress MixedOperand */
        $node->setAttribute('startLine', $attrs['startLine'] + $this->line_offset);
    }
1108944
private static function _getNodePath($node)
    {
        $ret = array();
        $doc = $node->ownerDocument;
        $parentNode = $node->parentNode;

        while ($parentNode !== null && !$doc->isSameNode($parentNode)) {
            // gets the sibling position
            $pos = 0;
            foreach ($parentNode->childNodes as $i => $childNode) {
                if ($childNode->isSameNode($node)) {
                    $pos = $i;
                    break;
                }
            }

            array_unshift($ret, $pos);
            $node = $parentNode;
            $parentNode = $node->parentNode;
        }

        return $ret;
    }
145567
public function leaveNode(Node $node)
    {
        if ($node instanceof Expr\ClassConstFetch
            && $node->name === 'class'
        ) {
            $class = $node->class;
            if (strcmp($class->toString(), 'static') === 0
                || strcmp($class->toString(), 'self') === 0
            ) {
                $name = Name::concat($this->namespaceNode, $this->classNode->name);
                return new Scalar\String_(trim($name->toString(), '\\'));
                // return new Expr\FuncCall(new Name('get_class'));
            }
            if ($class->isFullyQualified()) {
                return new Scalar\String_(trim($class->toString(), '\\'));
            }
            $prefix = $this->namespaceNode;
            foreach ($this->importNodes as $import) {
                if (strcmp($class->getFirst(), $import->getLast()) === 0) {
                    $prefix = $import->toString();
                    array_shift($class->parts);
                    break;
                }
            }
            $name = Name::concat($prefix, $class);
            return new Scalar\String_(trim($name->toString(), '\\'));
        }
    }
458582
public function enterNode(Node $node)
    {
        if ($node instanceof Namespace_) {
            // If this is the same namespace as last namespace, let's do ourselves
            // a favor and reload all the aliases...
            if (\strtolower($node->name) === \strtolower($this->lastNamespace)) {
                $this->aliases = $this->lastAliases;
            }
        }
    }
929845
public static function fromNode(Node $node): self
    {
        return new self($node::schema()->getQName(), (string)$node->get('_id'));
    }
674651
public function leaveNode(Node $node)
    {
        if ($node instanceof Class_) {
            // Build params
            $params = [];
            $paramComments = '';
            foreach ($this->params as $param) {
                if (is_array($param)) {
                    $params[] = isset($param['type']) && isset($param['name'])
                        ? new Param($param['name'], null, new Name([$param['type']]))
                        : new Param($param[0]);
                } else {
                    $params[] = new Param($param);
                }
                $paramComments .= '    * @param '
                    .(isset($param['type']) ? $param['type'] : 'mixed')
                    .' $'.(isset($param['name']) ? $param['name'] : $param)."\n";
            }
            if (count($params) > 0)
                $paramComments = '     *'."\n".$paramComments;
            // ADD statement
            $node->stmts[] = new ClassMethod(
                preg_replace('/\-\./', '_', $this->methodName),
                [
                    'type'      => 1,
                    'params'    => $params,
                ],
                [
                    'comments'  => [new Comment(sprintf(
                        '/**'."\n"
                            . (empty($this->comment) ? '' : '    * '.$this->comment."\n")
                            .'     * Ayuco: addition %s'."\n"
                            .'     * @since fill'."\n"
                            .$paramComments
                            .'     *'."\n"
                            .'     * @return'."\n"
                            .'     */',
                        date('Y-m-d h:i a'))
                    )]
                ]
            );
        }
    }
992693
public function leaveNode(Node $node, Environment $environment): Node
    {
        if (!($node instanceof ModuleNode)) {
            return $node;
        }

        if ($node->hasAttribute('embedded_templates')) {
            /** @var ModuleNode $embeddedTemplate */
            foreach ($node->getAttribute('embedded_templates') as $embeddedTemplate) {
                $embeddedTemplate->setAttribute('is_embedded', true);
            }
        }

        $node->setNode('display_start', new DisplayStartNode($node, $this));
        $node->setNode('display_end', new DisplayEndNode($node));

        return $node;
    }
618171
public function refactor(Node $node): ?Node
    {
        if (! $this->isName($node, 'parse')) {
            return null;
        }

        if (! $this->isType($node->class, 'Symfony\Component\Yaml\Yaml')) {
            return null;
        }

        if (! $this->isArgumentYamlFile($node)) {
            return null;
        }

        $fileGetContentsFunCallNode = $this->createFunction('file_get_contents', [$node->args[0]]);
        $node->args[0] = new Arg($fileGetContentsFunCallNode);

        return $node;
    }
216251
protected function appendChild(Node $node) {
    if ($this->tail === NULL) {
      $this->prependChild($node);
    }
    else {
      $this->insertAfterChild($this->tail, $node);
      $this->tail = $node;
    }
    return $this;
  }