OpenApi::getInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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 4
    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 4
        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 2
            $servers = new ServerCollection([new Server('/')]);
44
        }
45
46 4
        $this->openapi = $openapi;
47 4
        $this->info = $info;
48 4
        $this->paths = $paths;
49 4
        $this->servers = $servers;
50 4
        $this->components = $components;
51 4
        $this->security = $security;
52 4
        $this->tags = $tags;
53 4
        $this->externalDocs = $externalDocs;
54 4
        $this->extensions = $extensions;
55
    }
56
57 2
    public function getComponents(): Components
58
    {
59 2
        return $this->components;
60
    }
61
62 4
    public function getInfo(): Info
63
    {
64 4
        return $this->info;
65
    }
66
67 4
    public function getOpenapi(): string
68
    {
69 4
        return $this->openapi;
70
    }
71
72 4
    public function getPaths(): Paths
73
    {
74 4
        return $this->paths;
75
    }
76
77 2
    public function getTags(): TagCollection
78
    {
79 2
        return $this->tags;
80
    }
81
82 4
    public function hasComponents(): bool
83
    {
84 4
        return isset($this->components);
85
    }
86
87 4
    public function hasTags(): bool
88
    {
89 4
        return isset($this->tags);
90
    }
91
92 4
    public function jsonSerialize(): ?array
93
    {
94 4
        return $this->extendedProperties(parent::jsonSerialize());
95
    }
96
97 4
    protected function normalizeOptionalProperties(): array
98
    {
99
        return [
100 4
            'servers' => $this->getNormalizedServers(),
101 4
            'components' => $this->hasComponents() ? $this->getComponents()->jsonSerialize() : null,
102 4
            'security' => $this->getNormalizedSecurity(),
103 4
            'tags' => $this->hasTags() ? $this->getTags()->jsonSerialize() : null,
104 4
            'externalDocs' => $this->getNormalizedExternalDocs(),
105
        ];
106
    }
107
108 4
    protected function normalizeRequiredProperties(): array
109
    {
110
        return [
111 4
            'openapi' => $this->getOpenapi(),
112 4
            'info' => $this->getInfo()->jsonSerialize() ?: self::emptyObject(),
113 4
            'paths' => $this->getPaths()->jsonSerialize() ?: self::emptyObject(),
114
        ];
115
    }
116
}
117