Passed
Branch release/v2.0.0 (8dcb16)
by Anatoly
04:11 queued 17s
created

Parameter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 7
eloc 35
c 4
b 0
f 0
dl 0
loc 143
ccs 0
cts 30
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B toArray() 0 37 7
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\Annotation\OpenApi;
13
14
/**
15
 * @Annotation
16
 *
17
 * @Target({"ALL"})
18
 *
19
 * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameter-object
20
 */
21
final class Parameter extends AbstractAnnotation implements ParameterInterface
22
{
23
24
    /**
25
     * @Required
26
     *
27
     * @Enum({"cookie", "header", "query"})
28
     *
29
     * @var string
30
     *
31
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterin
32
     */
33
    public $in;
34
35
    /**
36
     * @Required
37
     *
38
     * @var string
39
     *
40
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parametername
41
     */
42
    public $name;
43
44
    /**
45
     * @var string
46
     *
47
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterdescription
48
     */
49
    public $description = '';
50
51
    /**
52
     * @var bool
53
     *
54
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterrequired
55
     */
56
    public $required = false;
57
58
    /**
59
     * @var bool
60
     *
61
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterdeprecated
62
     */
63
    public $deprecated = false;
64
65
    /**
66
     * @var bool
67
     *
68
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterallowemptyvalue
69
     */
70
    public $allowEmptyValue = false;
71
72
    /**
73
     * @Enum({"matrix", "label", "form", "simple", "spaceDelimited", "pipeDelimited", "deepObject"})
74
     *
75
     * @var string
76
     *
77
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterstyle
78
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#style-values
79
     */
80
    public $style;
81
82
    /**
83
     * @var bool
84
     *
85
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterexplode
86
     */
87
    public $explode;
88
89
    /**
90
     * @var bool
91
     *
92
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterallowreserved
93
     */
94
    public $allowReserved = false;
95
96
    /**
97
     * @var \Sunrise\Http\Router\Annotation\OpenApi\SchemaInterface
98
     *
99
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterschema
100
     */
101
    public $schema;
102
103
    /**
104
     * @var mixed
105
     *
106
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterexample
107
     */
108
    public $example;
109
110
    /**
111
     * @var array<\Sunrise\Http\Router\Annotation\OpenApi\ExampleInterface>
112
     *
113
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterexamples
114
     */
115
    public $examples = [];
116
117
    /**
118
     * @var array<\Sunrise\Http\Router\Annotation\OpenApi\MediaTypeInterface>
119
     *
120
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parametercontent
121
     */
122
    public $content = [];
123
124
    /**
125
     * {@inheritDoc}
126
     */
127
    public function toArray() : array
128
    {
129
        $result = [
130
            'in' => $this->in,
131
            'name' => $this->name,
132
            'description' => $this->description,
133
            'required' => $this->required,
134
            'deprecated' => $this->deprecated,
135
            'allowEmptyValue' => $this->allowEmptyValue,
136
            'allowReserved' => $this->allowReserved,
137
        ];
138
139
        if (isset($this->style)) {
140
            $result['style'] = $this->style;
141
        }
142
143
        if (isset($this->explode)) {
144
            $result['explode'] = $this->explode;
145
        }
146
147
        if (isset($this->schema)) {
148
            $result['schema'] = $this->schema->toArray();
149
        }
150
151
        if (isset($this->example)) {
152
            $result['example'] = $this->example;
153
        }
154
155
        foreach ($this->examples as $key => $value) {
156
            $result['examples'][$key] = $value->toArray();
157
        }
158
159
        foreach ($this->content as $key => $value) {
160
            $result['content'][$key] = $value->toArray();
161
        }
162
163
        return $result;
164
    }
165
}
166