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();
}