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

Components::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 9.552
c 0
b 0
f 0
cc 1
nc 1
nop 10
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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 Components extends ValueObject
11
{
12
    use Properties\OptionalExamples;
13
    use Properties\OptionalCallbacks;
14
    use Properties\OptionalExtensions;
15
16
    private $headers;
17
18
    private $links;
19
20
    private $parameters;
21
22
    private $requestBodies;
23
24
    private $responses;
25
26
    private $schemas;
27
28
    private $securitySchemes;
29
30 3
    public function __construct(
31
        Schemas $schemas = null,
32
        Responses $responses = null,
33
        Parameters $parameters = null,
34
        RequestBodies $requestBodies = null,
35
        Headers $headers = null,
36
        SecuritySchemes $securitySchemes = null,
37
        Links $links = null,
38
        CallbackRequests $callbacks = null,
39
        Examples $examples = null,
40
        Extensions $extensions = null
41
    ) {
42 3
        $this->schemas = $schemas;
43 3
        $this->responses = $responses;
44 3
        $this->parameters = $parameters;
45 3
        $this->requestBodies = $requestBodies;
46 3
        $this->headers = $headers;
47 3
        $this->securitySchemes = $securitySchemes;
48 3
        $this->links = $links;
49 3
        $this->callbacks = $callbacks;
50 3
        $this->examples = $examples;
51 3
        $this->extensions = $extensions;
52
    }
53
54 1
    public function getHeaders(): Headers
55
    {
56 1
        return $this->headers;
57
    }
58
59 1
    public function getLinks(): Links
60
    {
61 1
        return $this->links;
62
    }
63
64 1
    public function getParameters(): Parameters
65
    {
66 1
        return $this->parameters;
67
    }
68
69 1
    public function getRequestBodies(): RequestBodies
70
    {
71 1
        return $this->requestBodies;
72
    }
73
74 1
    public function getResponses(): Responses
75
    {
76 1
        return $this->responses;
77
    }
78
79 2
    public function getSchemas(): Schemas
80
    {
81 2
        return $this->schemas;
82
    }
83
84 1
    public function getSecuritySchemes(): SecuritySchemes
85
    {
86 1
        return $this->securitySchemes;
87
    }
88
89 3
    public function hasHeaders(): bool
90
    {
91 3
        return isset($this->headers);
92
    }
93
94 3
    public function hasLinks(): bool
95
    {
96 3
        return isset($this->links);
97
    }
98
99 3
    public function hasParameters(): bool
100
    {
101 3
        return isset($this->parameters);
102
    }
103
104 3
    public function hasRequestBodies(): bool
105
    {
106 3
        return isset($this->requestBodies);
107
    }
108
109 3
    public function hasResponses(): bool
110
    {
111 3
        return isset($this->responses);
112
    }
113
114 3
    public function hasSchemas(): bool
115
    {
116 3
        return isset($this->schemas);
117
    }
118
119 3
    public function hasSecuritySchemes(): bool
120
    {
121 3
        return isset($this->securitySchemes);
122
    }
123
124 3
    public function jsonSerialize(): ?array
125
    {
126 3
        return $this->extendedProperties(parent::jsonSerialize());
127
    }
128
129 3
    protected function normalizeOptionalProperties(): array
130
    {
131
        return [
132 3
            'schemas' => $this->hasSchemas() ? $this->getSchemas()->jsonSerialize() : null,
133 3
            'responses' => $this->hasResponses() ? $this->getResponses()->jsonSerialize() : null,
134 3
            'parameters' => $this->hasParameters() ? $this->getParameters()->jsonSerialize() : null,
135 3
            'requestBodies' => $this->hasRequestBodies() ? $this->getRequestBodies()->jsonSerialize() : null,
136 3
            'headers' => $this->hasHeaders() ? $this->getHeaders()->jsonSerialize() : null,
137 3
            'securitySchemes' => $this->hasSecuritySchemes() ? $this->getSecuritySchemes()->jsonSerialize() : null,
138 3
            'links' => $this->hasLinks() ? $this->getLinks() : null,
139 3
            'callbacks' => $this->getNormalizedCallbacks(),
140 3
            'examples' => $this->getNormalizedExamples(),
141
        ];
142
    }
143
}
144