/** * 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(array_filter(array_map(function (Type $type) { if (!$type->isGenericArray()) { return null; } return $type->genericArrayElementType(); }, $this->getTypeList()))); }
public function testFromStringWithClassWithMethodWithParameters() { $classType = MixedType::fromString("Skrz\\Meta\\Reflection\\Fixtures\\ClassWithMethodWithParameters"); $this->assertInstanceOf("Skrz\\Meta\\Reflection\\Type", $classType); $this->assertEquals("Skrz\\Meta\\Reflection\\Fixtures\\ClassWithMethodWithParameters", $classType->getName()); $method = $classType->getMethod("method"); $this->assertInstanceOf("Skrz\\Meta\\Reflection\\Method", $method); $parameters = $method->getParameters(); }