private function initialize() { $this->initialized = true; $parseResult = DocBlockParser::parsePropertyDocBlock($this->reflector); $this->description = $parseResult->description; $resolver = new Helper\ParserClassNameResolver($this->getDeclaringType()->getName()); $this->type = Type::of($parseResult->type, $resolver); }
public function testUnionType() { $fooInterface = Type::of("Hediet\\Types\\Test\\FooInterface"); $foo = Type::of("Hediet\\Types\\Test\\Foo"); $fooOrFooInterface = Type::ofUnion(array($fooInterface, $foo)); $this->assertTrue($fooOrFooInterface->equals($fooInterface)); $this->assertTrue(Type::ofUnion(array($fooInterface, Type::ofBoolean()))->isAssignableFrom($foo)); $this->assertTrue(Type::ofUnion(array($fooInterface, Type::ofBoolean()))->isAssignableFrom(Type::ofBoolean())); $this->assertFalse(Type::ofUnion(array($foo, Type::ofBoolean()))->isAssignableFrom($fooInterface)); $this->assertFalse(Type::ofUnion(array($foo, Type::ofBoolean()))->isAssignableFrom(Type::ofUnion(array($foo, Type::ofBoolean(), Type::ofNull())))); $this->assertTrue(Type::ofUnion(array($foo, Type::ofBoolean(), Type::ofNull()))->isAssignableFrom(Type::ofUnion(array(Type::ofBoolean(), $foo)))); }
/** * @param ReflectionParameter $parameter * @return Type */ function __internal_getParameterType(ReflectionParameter $parameter) { if (!isset($this->parameterTypeCache[$parameter->name])) { if (!$this->initialized) { $this->initialize(); } if (isset($this->parseResult->parameter[$parameter->getName()])) { $typeStr = $this->parseResult->parameter[$parameter->getName()]->type; $type = Type::of($typeStr, $this->resolver); } else { $typeHintedClass = $parameter->getClass(); if ($typeHintedClass !== null) { $type = Type::byReflectionClass($typeHintedClass); } else { $type = Type::ofMixed(); } if ($parameter->allowsNull()) { $type = Type::ofNullable($type); } } $this->parameterTypeCache[$parameter->name] = $type; } return $this->parameterTypeCache[$parameter->name]; }