FloatPhpTypeSchemaResolver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supportsPhpType() 0 3 1
A getWeight() 0 3 1
A resolvePhpTypeSchema() 0 8 2
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 Reflector;
17
use Sunrise\Http\Router\OpenApi\Exception\UnsupportedPhpTypeException;
18
use Sunrise\Http\Router\OpenApi\OpenApiPhpTypeSchemaResolverInterface;
19
use Sunrise\Http\Router\OpenApi\Type;
20
21
/**
22
 * @since 3.0.0
23
 */
24
final class FloatPhpTypeSchemaResolver implements OpenApiPhpTypeSchemaResolverInterface
25
{
26 3
    public function supportsPhpType(Type $phpType, Reflector $phpTypeHolder): bool
27
    {
28 3
        return $phpType->name === Type::PHP_TYPE_NAME_FLOAT;
29
    }
30
31
    /**
32
     * @inheritDoc
33
     */
34 3
    public function resolvePhpTypeSchema(Type $phpType, Reflector $phpTypeHolder): array
35
    {
36 3
        $this->supportsPhpType($phpType, $phpTypeHolder) or throw new UnsupportedPhpTypeException();
37
38 3
        return [
39 3
            'type' => Type::OAS_TYPE_NAME_NUMBER,
40 3
            'format' => 'double',
41 3
            'example' => 0.0,
42 3
        ];
43
    }
44
45 3
    public function getWeight(): int
46
    {
47 3
        return 0;
48
    }
49
}
50