resolvePhpTypeSchema()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 2
rs 10
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