Conditions | 5 |
Paths | 9 |
Total Lines | 207 |
Code Lines | 103 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
64 | public function getOpenApiSpec(): OASv3\Document |
||
65 | { |
||
66 | $paths = []; |
||
67 | foreach ($this->apiResources->getApiResources() as $apiResourceClass) { |
||
68 | $path = $this->converter->normalize($apiResourceClass); |
||
69 | $identifierName = $this->getIdentifierKey($apiResourceClass); |
||
70 | $paths['/' . $path] = $this->convertAllToPathItem($apiResourceClass, $path); |
||
71 | if ($identifierName) { |
||
72 | $paths['/' . $path . '/{' . $identifierName . '}'] = $this->convertToPathItem($apiResourceClass, $path, $identifierName); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | $stringSchema = new OASv3\Schema(['type' => 'string']); |
||
77 | $stringOrIntSchema = new OASv3\Schema(['oneOf' => [$stringSchema, new OASv3\Schema(['type' => 'integer'])]]); |
||
78 | $stringArraySchema = new OASv3\Schema(['type' => 'array', 'items' => $stringSchema]); |
||
79 | |||
80 | $errorSchema = new OASv3\Reference('#/components/schemas/Error'); |
||
81 | |||
82 | $validationErrorSchema = new OASv3\Schema([ |
||
83 | 'type' => 'object', |
||
84 | 'properties' => [ |
||
85 | 'type' => $stringSchema, |
||
86 | 'message' => $stringSchema, |
||
87 | 'code' => $stringOrIntSchema, |
||
88 | 'trace' => $stringSchema, |
||
89 | 'errors' => new OASv3\Schema([ |
||
90 | 'type' => 'object', |
||
91 | 'additionalProperties' => $stringArraySchema |
||
92 | ]), |
||
93 | ], |
||
94 | 'xml' => new OASv3\Xml(['name' => 'response']), |
||
95 | ]); |
||
96 | |||
97 | $doc = new OASv3\Document( |
||
98 | $this->info, |
||
99 | $paths, |
||
100 | '3.0.1', |
||
101 | [ |
||
102 | 'servers' => [ |
||
103 | new OASv3\Server($this->baseUrl), |
||
104 | ], |
||
105 | 'components' => new OASv3\Components([ |
||
106 | 'schemas' => [ |
||
107 | 'Error' => new OASv3\Schema([ |
||
108 | 'type' => 'object', |
||
109 | 'properties' => [ |
||
110 | 'type' => $stringSchema, |
||
111 | 'message' => $stringSchema, |
||
112 | 'code' => $stringOrIntSchema, |
||
113 | 'trace' => $stringSchema, |
||
114 | ], |
||
115 | 'xml' => new OASv3\Xml(['name' => 'response']), |
||
116 | ]), |
||
117 | ], |
||
118 | 'headers' => [ |
||
119 | 'x-ratelimit-limit' => new Oasv3\Header( |
||
120 | 'Request limit per hour', |
||
121 | [ |
||
122 | 'example' => 100, |
||
123 | 'schema' => new OASv3\Schema([ |
||
124 | 'type' => 'integer', |
||
125 | ]), |
||
126 | ] |
||
127 | ), |
||
128 | 'x-ratelimit-remaining' => new Oasv3\Header( |
||
129 | 'Request limit per hour', |
||
130 | [ |
||
131 | 'example' => 94, |
||
132 | 'schema' => new OASv3\Schema([ |
||
133 | 'type' => 'integer', |
||
134 | ]), |
||
135 | ] |
||
136 | ), |
||
137 | ], |
||
138 | 'responses' => [ |
||
139 | 'InvalidFormat' => new OASv3\Response( |
||
140 | 'The body input could not be parsed', |
||
141 | [ |
||
142 | 'application/json' => new OASv3\MediaType( |
||
143 | [ |
||
144 | 'schema' => $errorSchema, |
||
145 | ] |
||
146 | ), |
||
147 | 'application/xml' => new OASv3\MediaType( |
||
148 | [ |
||
149 | 'schema' => $errorSchema, |
||
150 | ] |
||
151 | ), |
||
152 | ] |
||
153 | ), |
||
154 | 'ValidationError' => new OASv3\Response( |
||
155 | 'The body input was in a proper format, but the input values were not valid', |
||
156 | [ |
||
157 | 'application/json' => new OASv3\MediaType( |
||
158 | [ |
||
159 | 'schema' => $validationErrorSchema, |
||
160 | ] |
||
161 | ), |
||
162 | 'application/xml' => new OASv3\MediaType( |
||
163 | [ |
||
164 | 'schema' => $validationErrorSchema, |
||
165 | ] |
||
166 | ), |
||
167 | ] |
||
168 | ), |
||
169 | 'TooManyRequests' => new OASv3\Response( |
||
170 | 'Too many requests per seconds were sent', |
||
171 | [ |
||
172 | 'application/json' => new OASv3\MediaType( |
||
173 | [ |
||
174 | 'schema' => $errorSchema, |
||
175 | ] |
||
176 | ), |
||
177 | 'application/xml' => new OASv3\MediaType( |
||
178 | [ |
||
179 | 'schema' => $errorSchema, |
||
180 | ] |
||
181 | ), |
||
182 | ] |
||
183 | ), |
||
184 | 'MaintenanceMode' => new OASv3\Response( |
||
185 | 'App is in maintenance mode', |
||
186 | [ |
||
187 | 'application/json' => new OASv3\MediaType( |
||
188 | [ |
||
189 | 'schema' => $errorSchema, |
||
190 | ] |
||
191 | ), |
||
192 | 'application/xml' => new OASv3\MediaType( |
||
193 | [ |
||
194 | 'schema' => $errorSchema, |
||
195 | ] |
||
196 | ), |
||
197 | ] |
||
198 | ), |
||
199 | 'NotFound' => new OASv3\Response( |
||
200 | 'Response when resource could not be found', |
||
201 | [ |
||
202 | 'application/json' => new OASv3\MediaType( |
||
203 | [ |
||
204 | 'schema' => $errorSchema, |
||
205 | ] |
||
206 | ), |
||
207 | 'application/xml' => new OASv3\MediaType( |
||
208 | [ |
||
209 | 'schema' => $errorSchema, |
||
210 | ] |
||
211 | ), |
||
212 | ] |
||
213 | ), |
||
214 | 'NotAuthorized' => new OASv3\Response( |
||
215 | 'You have no permission to do this call', |
||
216 | [ |
||
217 | 'application/json' => new OASv3\MediaType( |
||
218 | [ |
||
219 | 'schema' => $errorSchema, |
||
220 | ] |
||
221 | ), |
||
222 | 'application/xml' => new OASv3\MediaType( |
||
223 | [ |
||
224 | 'schema' => $errorSchema, |
||
225 | ] |
||
226 | ), |
||
227 | ] |
||
228 | ), |
||
229 | 'InternalError' => new OASv3\Response( |
||
230 | 'An internal error occured', |
||
231 | [ |
||
232 | 'application/json' => new OASv3\MediaType( |
||
233 | [ |
||
234 | 'schema' => $errorSchema, |
||
235 | ] |
||
236 | ), |
||
237 | 'application/xml' => new OASv3\MediaType( |
||
238 | [ |
||
239 | 'schema' => $errorSchema, |
||
240 | ] |
||
241 | ), |
||
242 | ] |
||
243 | ), |
||
244 | 'ServerDependencyError' => new OASv3\Response( |
||
245 | 'The server required an external response which threw an error', |
||
246 | [ |
||
247 | 'application/json' => new OASv3\MediaType( |
||
248 | [ |
||
249 | 'schema' => $errorSchema, |
||
250 | ] |
||
251 | ), |
||
252 | 'application/xml' => new OASv3\MediaType( |
||
253 | [ |
||
254 | 'schema' => $errorSchema, |
||
255 | ] |
||
256 | ), |
||
257 | ] |
||
258 | ), |
||
259 | ], |
||
260 | ]), |
||
261 | ] |
||
262 | ); |
||
263 | if (is_callable($this->addSpecsHook)) { |
||
264 | $res = call_user_func($this->addSpecsHook, $doc); |
||
265 | if ($res instanceof OASv3\Document) { |
||
266 | return $res; |
||
267 | } |
||
268 | } |
||
269 | |||
270 | return $doc; |
||
271 | } |
||
563 |