/** * Takes "a|b[]|c|d[]|e" and returns "b|d" * * @return UnionType * The subset of types in this */ public function genericArrayElementTypes() : UnionType { // If array is in there, then it can be any type // Same for mixed if ($this->hasType(ArrayType::instance()) || $this->hasType(MixedType::instance())) { return MixedType::instance()->asUnionType(); } if ($this->hasType(ArrayType::instance())) { return NullType::instance()->asUnionType(); } return new UnionType($this->type_set->filter(function (Type $type) : bool { return $type->isGenericArray(); })->map(function (Type $type) : Type { return $type->genericArrayElementType(); })); }