Пример #1
0
 public function testDescription()
 {
     $m = Type::ofObjectType("Hediet\\Types\\Test\\MyClass")->getMethod("myMethod");
     $this->assertEquals("Does some stuff.", $m->getDescription());
     $this->assertEquals("The return value.", $m->getResultInfo()->getDescription());
     /* @var $resultType ArrayType */
     $resultType = $m->getResultInfo()->getType();
     $this->assertEquals("string[]", $resultType->getName());
     $this->assertEquals("string", $resultType->getItemType()->getName());
     $this->assertTrue($resultType->isAssignableFromValue(array("str1", "str2")));
     $this->assertFalse($resultType->isAssignableFromValue(array(1, 2)));
     $this->assertFalse($resultType->isAssignableFrom(Type::ofMixed()));
     $this->assertTrue(Type::ofMixed()->isAssignableFrom($resultType));
     $myArgParam = $m->getParameters()[0];
     $this->assertEquals("myArg", $myArgParam->getName());
     $this->assertEquals("Some input.", $myArgParam->getDescription());
     $this->assertEquals("Hediet\\Types\\Test\\MyClass|Hediet\\Types\\Type", $myArgParam->getType()->getName());
 }
 /**
  * @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];
 }
Пример #3
0
 /**
  * Gets an array type which elements are of type $itemType.
  * 
  * @param Type $itemType The type of the elements.
  * @return ArrayType
  */
 public static function ofArray(Type $itemType)
 {
     return ArrayType::__internal_create(Type::ofMixed(), $itemType);
 }