Phan\Analysis\PostOrderAnalysisVisitor::visitDim PHP Method

visitDim() public method

Visit a node with kind \ast\AST_DIM
public visitDim ( ast\Node $node ) : Context
$node ast\Node A node to parse
return Phan\Language\Context A new or an unchanged context resulting from parsing the node
    public function visitDim(Node $node) : Context
    {
        // Check the array type to trigger
        // TypeArraySuspicious
        try {
            $array_type = UnionType::fromNode($this->context, $this->code_base, $node, false);
        } catch (IssueException $exception) {
            // Swallow it. We'll deal with issues elsewhere
        }
        if (!Config::get()->backward_compatibility_checks) {
            return $this->context;
        }
        if (!($node->children['expr'] instanceof Node && ($node->children['expr']->children['name'] ?? null) instanceof Node)) {
            return $this->context;
        }
        // check for $$var[]
        if ($node->children['expr']->kind == \ast\AST_VAR && $node->children['expr']->children['name']->kind == \ast\AST_VAR) {
            $temp = $node->children['expr']->children['name'];
            $depth = 1;
            while ($temp instanceof Node) {
                assert(isset($temp->children['name']), "Expected to find a name in context, something else found.");
                $temp = $temp->children['name'];
                $depth++;
            }
            $dollars = str_repeat('$', $depth);
            $ftemp = new \SplFileObject($this->context->getFile());
            $ftemp->seek($node->lineno - 1);
            $line = $ftemp->current();
            unset($ftemp);
            if (strpos($line, '{') === false || strpos($line, '}') === false) {
                $this->emitIssue(Issue::CompatibleExpressionPHP7, $node->lineno ?? 0, "{$dollars}{$temp}[]");
            }
            // $foo->$bar['baz'];
        } elseif (!empty($node->children['expr']->children[1]) && $node->children['expr']->children[1] instanceof Node && $node->children['expr']->kind == \ast\AST_PROP && $node->children['expr']->children[0]->kind == \ast\AST_VAR && $node->children['expr']->children[1]->kind == \ast\AST_VAR) {
            $ftemp = new \SplFileObject($this->context->getFile());
            $ftemp->seek($node->lineno - 1);
            $line = $ftemp->current();
            unset($ftemp);
            if (strpos($line, '{') === false || strpos($line, '}') === false) {
                $this->emitIssue(Issue::CompatiblePHP7, $node->lineno ?? 0);
            }
        }
        return $this->context;
    }