Phan\AST\UnionTypeVisitor::visitArray PHP Method

visitArray() public method

Visit a node with kind \ast\AST_ARRAY
public visitArray ( ast\Node $node ) : UnionType
$node ast\Node A node of the type indicated by the method name that we'd like to figure out the type that it produces.
return Phan\Language\UnionType The set of types that are possibly produced by the given node
    public function visitArray(Node $node) : UnionType
    {
        if (!empty($node->children) && $node->children[0] instanceof Node && $node->children[0]->kind == \ast\AST_ARRAY_ELEM) {
            $element_types = [];
            // Check the first 5 (completely arbitrary) elements
            // and assume the rest are the same type
            for ($i = 0; $i < 5; $i++) {
                // Check to see if we're out of elements
                if (empty($node->children[$i])) {
                    break;
                }
                if ($node->children[$i]->children['value'] instanceof Node) {
                    $element_types[] = UnionType::fromNode($this->context, $this->code_base, $node->children[$i]->children['value'], $this->should_catch_issue_exception);
                } else {
                    $element_types[] = Type::fromObject($node->children[$i]->children['value'])->asUnionType();
                }
            }
            $element_types = array_values(array_unique($element_types));
            if (count($element_types) == 1) {
                return $element_types[0]->asGenericArrayTypes();
            }
        }
        return ArrayType::instance()->asUnionType();
    }