StreamPhpTypeSchemaResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A resolvePhpTypeSchema() 0 7 2
A getWeight() 0 3 1
A supportsPhpType() 0 3 1
1
<?php
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Nekhay <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Nekhay
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
declare(strict_types=1);
13
14
namespace Sunrise\Http\Router\OpenApi\PhpTypeSchemaResolver;
15
16
use Psr\Http\Message\StreamInterface;
17
use Reflector;
18
use Sunrise\Http\Router\OpenApi\Exception\UnsupportedPhpTypeException;
19
use Sunrise\Http\Router\OpenApi\OpenApiPhpTypeSchemaResolverInterface;
20
use Sunrise\Http\Router\OpenApi\Type;
21
22
/**
23
 * @since 3.0.0
24
 */
25
final class StreamPhpTypeSchemaResolver implements OpenApiPhpTypeSchemaResolverInterface
26
{
27 3
    public function supportsPhpType(Type $phpType, Reflector $phpTypeHolder): bool
28
    {
29 3
        return $phpType->name === StreamInterface::class;
30
    }
31
32
    /**
33
     * @inheritDoc
34
     */
35 3
    public function resolvePhpTypeSchema(Type $phpType, Reflector $phpTypeHolder): array
36
    {
37 3
        $this->supportsPhpType($phpType, $phpTypeHolder) or throw new UnsupportedPhpTypeException();
38
39 3
        return [
40 3
            'type' => Type::OAS_TYPE_NAME_STRING,
41 3
            'format' => 'binary',
42 3
        ];
43
    }
44
45 3
    public function getWeight(): int
46
    {
47 3
        return 0;
48
    }
49
}
50