Пример #1
0
 /**
  * Extracts data from the PHP 7 reflection type.
  *
  * @param \ReflectionType $reflectionType
  *
  * @return Type
  */
 private function extractFromReflectionType(\ReflectionType $reflectionType)
 {
     $phpTypeOrClass = $reflectionType instanceof \ReflectionNamedType ? $reflectionType->getName() : $reflectionType->__toString();
     $nullable = $reflectionType->allowsNull();
     if (Type::BUILTIN_TYPE_ARRAY === $phpTypeOrClass) {
         $type = new Type(Type::BUILTIN_TYPE_ARRAY, $nullable, null, true);
     } elseif ('void' === $phpTypeOrClass) {
         $type = new Type(Type::BUILTIN_TYPE_NULL, $nullable);
     } elseif ($reflectionType->isBuiltin()) {
         $type = new Type($phpTypeOrClass, $nullable);
     } else {
         $type = new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $phpTypeOrClass);
     }
     return $type;
 }
Пример #2
0
 public static function castType(\ReflectionType $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     $a += array($prefix . 'name' => method_exists('ReflectionType', 'getName') ? $c->getName() : $c->__toString(), $prefix . 'allowsNull' => $c->allowsNull(), $prefix . 'isBuiltin' => $c->isBuiltin());
     return $a;
 }
 public function testGetName()
 {
     $this->assertSame('array', $this->t1->getName());
     $this->assertSame('\\Exception', $this->t2->getName());
 }