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

Operation::normalizeOptionalProperties()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 9.7333
c 0
b 0
f 0
cc 4
nc 8
nop 0
crap 4
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 Operation extends ValueObject
11
{
12
    use Properties\OptionalDeprecationStatus;
13
    use Properties\OptionalDescription;
14
    use Properties\OptionalExternalDocs;
15
    use Properties\OptionalExtensions;
16
    use Properties\OptionalServers;
17
    use Properties\OptionalSummary;
18
    use Properties\OptionalSecurityRequirements;
19
    use Properties\OptionalParameterCollection;
20
    use Properties\OptionalCallbacks;
21
22
    private $operationId;
23
24
    private $requestBody;
25
26
    private $responses;
27
28
    private $tags;
29
30 3
    public function __construct(
31
        OperationResponses $responses,
32
        RequestBody $requestBody = null,
33
        array $tags = [],
34
        string $operationId = null,
35
        string $summary = null,
36
        string $description = null,
37
        bool $deprecated = false,
38
        ParameterCollection $parameters = null,
39
        SecurityRequirementCollection $security = null,
40
        CallbackRequests $callbacks = null,
41
        ServerCollection $servers = null,
42
        ExternalDocumentation $externalDocs = null,
43
        Extensions $extensions = null
44
    ) {
45 3
        $this->responses = $responses;
46 3
        $this->requestBody = $requestBody;
47 3
        $this->tags = $tags;
48 3
        $this->operationId = $operationId;
49 3
        $this->summary = $summary;
50 3
        $this->description = $description;
51 3
        $this->deprecated = $deprecated;
52 3
        $this->parameters = $parameters;
53 3
        $this->security = $security;
54 3
        $this->callbacks = $callbacks;
55 3
        $this->servers = $servers;
56 3
        $this->externalDocs = $externalDocs;
57 3
        $this->extensions = $extensions;
58
    }
59
60 1
    public function getOperationId(): string
61
    {
62 1
        return $this->operationId;
63
    }
64
65 1
    public function getRequestBody(): ValueObject
66
    {
67 1
        return $this->requestBody;
68
    }
69
70 3
    public function getResponses(): OperationResponses
71
    {
72 3
        return $this->responses;
73
    }
74
75 3
    public function getTags(): array
76
    {
77 3
        return $this->tags;
78
    }
79
80 3
    public function hasOperationId(): bool
81
    {
82 3
        return isset($this->operationId);
83
    }
84
85 3
    public function hasRequestBody(): bool
86
    {
87 3
        return isset($this->requestBody);
88
    }
89
90 3
    public function jsonSerialize(): ?array
91
    {
92 3
        return $this->extendedProperties(parent::jsonSerialize());
93
    }
94
95 3
    protected function normalizeOptionalProperties(): array
96
    {
97
        return [
98 3
            'requestBody' => $this->hasRequestBody() ? $this->getRequestBody()->jsonSerialize() : null,
99 3
            'tags' => $this->getTags(),
100 3
            'operationId' => $this->hasOperationId() ? $this->getOperationId() : null,
101 3
            'summary' => $this->getNormalizedSummary(),
102 3
            'description' => $this->getNormalizedDescription(),
103 3
            'deprecated' => $this->isDeprecated() ?: null,
104 3
            'parameters' => $this->getNormalizedParameters(),
105 3
            'security' => $this->getNormalizedSecurity(),
106 3
            'callbacks' => $this->getNormalizedCallbacks(),
107 3
            'servers' => $this->getNormalizedServers(),
108 3
            'externalDocs' => $this->getNormalizedExternalDocs(),
109
        ];
110
    }
111
112 3
    protected function normalizeRequiredProperties(): array
113
    {
114
        return [
115 3
            'responses' => $this->getResponses()->jsonSerialize() ?: self::emptyObject(),
116
        ];
117
    }
118
}
119