Completed
Push — master ( 935a4f...80b369 )
by Veaceslav
01:53
created

OpenApi   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 11
dl 0
loc 107
ccs 38
cts 38
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 27 3
A getComponents() 0 4 1
A getInfo() 0 4 1
A getOpenapi() 0 4 1
A getPaths() 0 4 1
A getTags() 0 4 1
A hasComponents() 0 4 1
A hasTags() 0 4 1
A jsonSerialize() 0 4 1
A normalizeOptionalProperties() 0 10 3
A normalizeRequiredProperties() 0 8 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aweapi\Openapi\Objects;
6
7
use Aweapi\Openapi\Extensions;
8
use Aweapi\Openapi\ValueObject;
9
10
final class OpenApi extends ValueObject
11
{
12
    use Properties\OptionalExternalDocs;
13
    use Properties\OptionalExtensions;
14
    use Properties\OptionalSecurityRequirements;
15
    use Properties\Servers;
16
17
    public const LATEST_VERSION = '3.0.2';
18
19
    private $components;
20
21
    private $info;
22
23
    private $openapi;
24
25
    private $paths;
26
27
    private $tags;
28
29 2
    public function __construct(
30
        string $openapi,
31
        Info $info,
32
        Paths $paths,
33
        ServerCollection $servers = null,
34
        Components $components = null,
35
        SecurityRequirementCollection $security = null,
36
        TagCollection $tags = null,
37
        ExternalDocumentation $externalDocs = null,
38
        Extensions $extensions = null
39
    ) {
40 2
        if (!$servers || !$servers->hasItems()) {
41
            // If the servers property is not provided, or is an empty array,
42
            // the default value would be a Server Object with a url value of `/`.
43 1
            $servers = new ServerCollection([new Server('/')]);
44
        }
45
46 2
        $this->openapi = $openapi;
47 2
        $this->info = $info;
48 2
        $this->paths = $paths;
49 2
        $this->servers = $servers;
50 2
        $this->components = $components;
51 2
        $this->security = $security;
52 2
        $this->tags = $tags;
53 2
        $this->externalDocs = $externalDocs;
54 2
        $this->extensions = $extensions;
55
    }
56
57 1
    public function getComponents(): Components
58
    {
59 1
        return $this->components;
60
    }
61
62 2
    public function getInfo(): Info
63
    {
64 2
        return $this->info;
65
    }
66
67 2
    public function getOpenapi(): string
68
    {
69 2
        return $this->openapi;
70
    }
71
72 2
    public function getPaths(): Paths
73
    {
74 2
        return $this->paths;
75
    }
76
77 1
    public function getTags(): TagCollection
78
    {
79 1
        return $this->tags;
80
    }
81
82 2
    public function hasComponents(): bool
83
    {
84 2
        return isset($this->components);
85
    }
86
87 2
    public function hasTags(): bool
88
    {
89 2
        return isset($this->tags);
90
    }
91
92 2
    public function jsonSerialize(): ?array
93
    {
94 2
        return $this->extendedProperties(parent::jsonSerialize());
95
    }
96
97 2
    protected function normalizeOptionalProperties(): array
98
    {
99
        return [
100 2
            'servers' => $this->getNormalizedServers(),
101 2
            'components' => $this->hasComponents() ? $this->getComponents()->jsonSerialize() : null,
102 2
            'security' => $this->getNormalizedSecurity(),
103 2
            'tags' => $this->hasTags() ? $this->getTags()->jsonSerialize() : null,
104 2
            'externalDocs' => $this->getNormalizedExternalDocs(),
105
        ];
106
    }
107
108 2
    protected function normalizeRequiredProperties(): array
109
    {
110
        return [
111 2
            'openapi' => $this->getOpenapi(),
112 2
            'info' => $this->getInfo()->jsonSerialize() ?: self::emptyObject(),
113 2
            'paths' => $this->getPaths()->jsonSerialize() ?: self::emptyObject(),
114
        ];
115
    }
116
}
117