コード例 #1
0
ファイル: TypehintHelper.php プロジェクト: phpstan/phpstan
 public static function decideType(Type $type, Type $phpDocType = null) : Type
 {
     if ($phpDocType !== null) {
         if ($type instanceof IterableType && $phpDocType instanceof ArrayType) {
             if ($type instanceof IterableIterableType) {
                 $phpDocType = new IterableIterableType($phpDocType->getItemType(), $type->isNullable() || $phpDocType->isNullable());
             } elseif ($type instanceof ArrayType) {
                 $type = new ArrayType($phpDocType->getItemType(), $type->isNullable() || $phpDocType->isNullable());
             }
         }
         if ($type->accepts($phpDocType)) {
             return $phpDocType;
         }
     }
     return $type;
 }
コード例 #2
0
ファイル: TypehintHelper.php プロジェクト: phpstan/phpstan
 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;
 }