Example #1
0
 public function accepts(Type $type) : bool
 {
     if ($type instanceof self) {
         return $this->getItemType()->accepts($type->getItemType());
     }
     if ($type instanceof MixedType) {
         return true;
     }
     if ($this->isNullable() && $type instanceof NullType) {
         return true;
     }
     return false;
 }
Example #2
0
 public function accepts(Type $type) : bool
 {
     if ($type instanceof IterableType) {
         return $this->getItemType()->accepts($type->getItemType());
     }
     if ($type->getClass() !== null && $this->exists($type->getClass())) {
         $classReflection = new \ReflectionClass($type->getClass());
         return $classReflection->implementsInterface(\Traversable::class);
     }
     if ($type instanceof MixedType) {
         return true;
     }
     if ($this->isNullable() && $type instanceof NullType) {
         return true;
     }
     return false;
 }
Example #3
0
 public static function decideType(\ReflectionType $reflectionType = null, Type $phpDocType = null, string $selfClass = null, bool $isVariadic = false) : Type
 {
     if ($reflectionType === null) {
         return $phpDocType !== null ? $phpDocType : new MixedType(true);
     }
     $reflectionTypeString = (string) $reflectionType;
     if ($isVariadic) {
         $reflectionTypeString .= '[]';
     }
     $type = self::getTypeObjectFromTypehint($reflectionTypeString, $reflectionType->allowsNull(), $selfClass);
     if ($phpDocType !== null) {
         if ($type instanceof ArrayType && $phpDocType instanceof ArrayType) {
             $type = new ArrayType($phpDocType->getItemType(), $type->isNullable() || $phpDocType->isNullable());
         }
         if ($type->accepts($phpDocType)) {
             return $phpDocType;
         }
     }
     return $type;
 }