Swap out __DIR__ and __FILE__ constants, because the default ones when
calling eval() don't make sense.

@param Node $node

@return null|FuncCall|String_
185292
public function enterNode(Node $node)
    {
        if ($node instanceof Dir) {
            return new FuncCall(new Name('getcwd'), [], $node->getAttributes());
        } elseif ($node instanceof File) {
            return new String_('', $node->getAttributes());
        }
    }
308648
public function run(string $file, Node $node): array
    {
        $cond = $node->children['cond'];
        $true = $node->children['true'];

        if ($cond instanceof Node && $cond->kind === \ast\AST_ISSET) {
            $var = $cond->children['var'];

            // If both are Node (Object), using the comparison operator.
            if (is_object($var) && is_object($true)) {
                if ($var != $true) {
                    Logger::getInstance()->debug('Different node found. Ignore it: '.$node->lineno);
                    return [];
                }
            // If it is not an object, using the identity operator.
            } else {
                if ($var !== $true) {
                    Logger::getInstance()->debug('Ignore: '.$node->lineno);
                    return [];
                }
            }

            return [new Hint(
                self::HINT_TYPE,
                self::HINT_MESSAGE,
                $file,
                $node->lineno,
                self::HINT_LINK
            )];
        }

        return [];
    }
1254966
public function createRoot(Node $node)
    {
        if($node instanceof NodeWrapper)
        {
            throw new \InvalidArgumentException('Can\'t create a root node from a NodeWrapper node');
        }

        $node->setLeftValue(1);
        $node->setRightValue(2);

        if($this->getConfiguration()->hasManyRoots())
        {
            $rootValue = $node->getId();
            if($rootValue === null)
            {
                // Set a temporary value in case wrapped node requires root value to be set
                $node->setRootValue(0);
                $this->getEntityManager()->persist($node);
                $this->getEntityManager()->flush();
                $rootValue = $node->getId();
            }

            if($rootValue === null)
            {
                // @codeCoverageIgnoreStart
                throw new \RuntimeException('Node must have an identifier available via getId()');
                // @codeCoverageIgnoreEnd
            }

            $node->setRootValue($rootValue);
        }


        $this->getEntityManager()->persist($node);
        $this->getEntityManager()->flush();

        return $this->wrapNode($node);
    }
804122
public function mutate(Node $node)
    {
        return new Node\Stmt\For_(
            [
                'init' => $node->init,
                'cond' => [new Node\Expr\ConstFetch(new Node\Name('false'))],
                'loop' => $node->loop,
                'stmts' => $node->stmts,
            ],
            $node->getAttributes()
        );
    }
741137
public function parseExpressionNode(Node\Expr $node)
    {
        switch (true) {
            case $mappedNode = $this->parseOperatorNode($node):
                return $mappedNode;

            case $node instanceof Node\Scalar
                    && $mappedNode = $this->parseScalarNode($node):
                return $mappedNode;

            case $node instanceof Node\Expr\Variable:
                return Expression::variable($this->parseNameNode($node->name));

            case $node instanceof Node\Expr\Array_:
                return $this->parseArrayNode($node);

            case $node instanceof Node\Expr\FuncCall:
                return $this->parseFunctionCallNode($node);

            case $node instanceof Node\Expr\New_:
                return Expression::newExpression(
                        $this->parseNameNode($node->class),
                        $this->parseNodes($node->args)
                );

            case $node instanceof Node\Expr\MethodCall:
                return Expression::methodCall(
                        $this->parseNode($node->var),
                        $this->parseNameNode($node->name),
                        $this->parseNodes($node->args)
                );

            case $node instanceof Node\Expr\PropertyFetch:
                return Expression::field(
                        $this->parseNode($node->var),
                        $this->parseNameNode($node->name)
                );

            case $node instanceof Node\Expr\ArrayDimFetch:
                return Expression::index(
                        $this->parseNode($node->var),
                        $node->dim === null ? null : $this->parseNode($node->dim)
                );

            case $node instanceof Node\Expr\ConstFetch:
                return Expression::constant($this->parseAbsoluteName($node->name));

            case $node instanceof Node\Expr\ClassConstFetch:
                return Expression::classConstant(
                        $this->parseNameNode($node->class),
                        $node->name
                );

            case $node instanceof Node\Expr\StaticCall:
                return Expression::staticMethodCall(
                        $this->parseNameNode($node->class),
                        $this->parseNameNode($node->name),
                        $this->parseNodes($node->args)
                );

            case $node instanceof Node\Expr\StaticPropertyFetch:
                return Expression::staticField(
                        $this->parseNameNode($node->class),
                        $this->parseNameNode($node->name)
                );

            case $node instanceof Node\Expr\Ternary:
                return $this->parseTernaryNode($node);

            case $node instanceof Node\Expr\Closure:
                return $this->parseClosureNode($node);

            case $node instanceof Node\Expr\Empty_:
                return Expression::emptyExpression($this->parseNode($node->expr));

            case $node instanceof Node\Expr\Isset_:
                return Expression::issetExpression($this->parseNodes($node->vars));

            default:
                throw new ASTException(
                        'Cannot parse AST with unknown expression node: %s',
                        get_class($node));
        }
    }
86081
final public function mutate(Node $node)
    {
        foreach ($this->getParameterIndexes($node) as $index) {
            yield $node->args[$index];
        }
    }
879514
private function getCallingInfo(Node $node)
    {
        return coroutine(function () use ($node) {
            $fqn = null;
            $callingNode = null;
            if ($node instanceof Node\DelimitedList\ArgumentExpressionList) {
                // Cursor is already inside a (
                $argumentExpressionList = $node;
                if ($node->parent instanceof Node\Expression\ObjectCreationExpression) {
                    // Constructing something
                    $callingNode = $node->parent->classTypeDesignator;
                    if (!$callingNode instanceof Node\QualifiedName) {
                        // We only support constructing from a QualifiedName
                        return null;
                    }
                    $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($callingNode);
                    $fqn = "{$fqn}->__construct()";
                } else {
                    $callingNode = $node->parent->getFirstChildNode(
                        Node\Expression\MemberAccessExpression::class,
                        Node\Expression\ScopedPropertyAccessExpression::class,
                        Node\QualifiedName::class
                    );
                }
            } elseif ($node instanceof Node\Expression\CallExpression) {
                $argumentExpressionList = $node->getFirstChildNode(Node\DelimitedList\ArgumentExpressionList::class);
                $callingNode = $node->getFirstChildNode(
                    Node\Expression\MemberAccessExpression::class,
                    Node\Expression\ScopedPropertyAccessExpression::class,
                    Node\QualifiedName::class
                );
            } elseif ($node instanceof Node\Expression\ObjectCreationExpression) {
                $argumentExpressionList = $node->getFirstChildNode(Node\DelimitedList\ArgumentExpressionList::class);
                $callingNode = $node->classTypeDesignator;
                if (!$callingNode instanceof Node\QualifiedName) {
                    // We only support constructing from a QualifiedName
                    return null;
                }
                // Manually build the __construct fqn
                $fqn = $this->definitionResolver->resolveReferenceNodeToFqn($callingNode);
                $fqn = "{$fqn}->__construct()";
            }

            if (!$callingNode) {
                return null;
            }

            // Now find the definition of the call
            $fqn = $fqn ?: DefinitionResolver::getDefinedFqn($callingNode);
            while (true) {
                if ($fqn) {
                    $def = $this->index->getDefinition($fqn);
                } else {
                    $def = $this->definitionResolver->resolveReferenceNodeToDefinition($callingNode);
                }
                if ($def !== null || $this->index->isComplete()) {
                    break;
                }
                yield waitForEvent($this->index, 'definition-added');
            }

            if (!$def) {
                return null;
            }

            return [$def, $argumentExpressionList];
        });
    }
333755
private function switchToNode(Node $node)
    {
        $nodeId = $node->getId();
        // Return early if we're trying to switch to the current node.
        if (($this->nodeId === $nodeId)) {
            // But return early only if the current node is connected to Disque.
            // If it is disconnected, we want to overwrite it with the node
            // from the method argument, because that one is connected.
            if ($this->getCurrentNode()->isConnected()) {
                return;
            }

            // Copy the stats from the now-disconnected node object
            $this->copyNodeStats($this->getCurrentNode(), $node);
        }

        $this->resetNodeCounters();

        $this->nodeId = $nodeId;
        $this->nodes[$nodeId] = $node;
        $this->revealClusterFromHello($node);
    }
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;
    }
600848
private function replaceElementsWithPara(Element $node): ?self {
        // Check to see if the node no longer exist.
        // 'Ghost' nodes have their ownerDocument property set to null - will throw a warning on access.
        // Use another common property with isset() - won't throw any warnings.
        if (!isset($node->nodeName)) {
            return null;
        }

        $newEl = $this->document()->createElement('p');

        $newEl->append($node->contents()->detach());

        foreach ($node->attributes as $attr) {
            $newEl->attr($attr->localName, $attr->nodeValue);
        }

        $node->replaceWith($newEl);

        return $this;
    }
1121022
public function &detach(Node $node)
    {
        foreach ($this->links as $linked_node) {
            if ($linked_node == $node) {
                $this->links->detach($node);
            }
        }

        return $this;
    }
1159030
public function mutate(Node $node)
    {
        $node->value = new Node\Expr\BinaryOp\Greater($node->key, $node->value, $node->getAttributes());
        $node->key = null;

        return $node;
    }
750618
public function leaveNode(Node $node)
    {
        $filter = $this->filter;

        if (! $node instanceof ClassMethod || null === ($filterResult = $filter($node))) {
            return null;
        }

        if (false === $filterResult) {
            return false;
        }

        $node->stmts = array(
            new Throw_(
                new New_(
                    new FullyQualified('BadMethodCallException'),
                    array(new Arg(new String_('Method is disabled')))
                )
            )
        );

        return $node;
    }
385877
public function leaveNode(Node $node)
    {
        if ($node instanceof Stmt\GroupUse) {
            $nodes = [];
            foreach ($node->uses as $use) {
                $name = Name::concat($node->prefix, $use->name);
                $nodes[] = new Stmt\Use_([new Stmt\UseUse($name)]);
            }
            return $nodes;
        }
    }
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'))
                    )]
                ]
            );
        }
    }
1172
private function getContainingClassType(Node $node)
    {
        $classFqn = $this->getContainingClassFqn($node);
        return $classFqn ? new Types\Object_(new Fqsen('\\' . $classFqn)) : null;
    }
939678
private function getModifiedVariableNames(Node $node)
    {
        switch (true) {
            case $node instanceof Node\Stmt\Foreach_:
                return $this->extractModifiedVariableNames(array($node->keyVar, $node->valueVar));

            case $node instanceof Node\Stmt\Unset_:
                $modifiedNames = $this->extractModifiedVariableNames($node->vars);
                $scope = $this->getCurrentScope();
                foreach ($modifiedNames as $name) {
                    $scope->unsetVariable($name);
                }

                return $modifiedNames;

            case $node instanceof Node\Stmt\Global_:
            case $node instanceof Node\Expr\List_:
                return $this->extractModifiedVariableNames($node->vars);

            case $node instanceof Node\Expr\Assign:
            case $node instanceof Node\Expr\AssignOp:
            case $node instanceof Node\Expr\PostDec:
            case $node instanceof Node\Expr\PostInc:
            case $node instanceof Node\Expr\PreDec:
            case $node instanceof Node\Expr\PreInc:
                return $this->extractModifiedVariableNames(array($node->var));

            case $node instanceof Node\Expr\FuncCall:
            case $node instanceof Node\Expr\StaticCall:
            case $node instanceof Node\Expr\MethodCall:
                $byReferenceArguments = $this->functionAnalyzer->getByReferenceCallArguments($node);

                return $this->extractModifiedVariableNames($byReferenceArguments);

            case $node instanceof Node\Expr\AssignRef:
                return $this->addVariableReference($node);

            default:
                throw new \InvalidArgumentException(sprintf('Unknown node type %s', get_class($node)));
        }
    }