@@ -55,11 +55,11 @@ discard block |
||
55 | 55 | */ |
56 | 56 | private function getApiList(string $version): array |
57 | 57 | { |
58 | - $versionApis = array_filter($this->apiDecider->getApis(), function (Api $api) use ($version) { |
|
58 | + $versionApis = array_filter($this->apiDecider->getApis(), function(Api $api) use ($version) { |
|
59 | 59 | return $version === $api->getEndpoint()->getVersion(); |
60 | 60 | }); |
61 | 61 | |
62 | - return array_map(function (Api $api) { |
|
62 | + return array_map(function(Api $api) { |
|
63 | 63 | return [ |
64 | 64 | 'method' => $api->getEndpoint()->getMethod(), |
65 | 65 | 'version' => $api->getEndpoint()->getVersion(), |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | private function createParamsList(ApiHandlerInterface $handler): array |
83 | 83 | { |
84 | - return array_map(function (InputParam $param) { |
|
84 | + return array_map(function(InputParam $param) { |
|
85 | 85 | $parameter = [ |
86 | 86 | 'type' => $param->getType(), |
87 | 87 | 'key' => $param->getKey(), |
@@ -10,11 +10,11 @@ |
||
10 | 10 | { |
11 | 11 | public function validateSchema(): bool |
12 | 12 | { |
13 | - return !Debugger::$productionMode; |
|
13 | + return ! Debugger::$productionMode; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | public function showErrorDetail(): bool |
17 | 17 | { |
18 | - return !Debugger::$productionMode; |
|
18 | + return ! Debugger::$productionMode; |
|
19 | 19 | } |
20 | 20 | } |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | return new ValidationResult(ValidationResult::STATUS_ERROR, ['missing data']); |
47 | 47 | } |
48 | 48 | |
49 | - if (!empty($this->rawInput) && json_last_error()) { |
|
49 | + if ( ! empty($this->rawInput) && json_last_error()) { |
|
50 | 50 | return new ValidationResult(ValidationResult::STATUS_ERROR, [json_last_error_msg()]); |
51 | 51 | } |
52 | 52 | |
53 | - if (!$value && $this->isRequired() === self::OPTIONAL) { |
|
53 | + if ( ! $value && $this->isRequired() === self::OPTIONAL) { |
|
54 | 54 | return new ValidationResult(ValidationResult::STATUS_OK); |
55 | 55 | } |
56 | 56 | |
@@ -68,19 +68,19 @@ discard block |
||
68 | 68 | { |
69 | 69 | $fullSchema = json_decode($this->schema, true); |
70 | 70 | |
71 | - if (!empty($examples = $this->getExamples())) { |
|
71 | + if ( ! empty($examples = $this->getExamples())) { |
|
72 | 72 | if (count($examples) === 1) { |
73 | - $fullSchema['example'] = is_array($this->getExample())? $this->getExample() : json_decode($this->getExample(), true); |
|
73 | + $fullSchema['example'] = is_array($this->getExample()) ? $this->getExample() : json_decode($this->getExample(), true); |
|
74 | 74 | } else { |
75 | 75 | foreach ($examples as $exampleKey => $example) { |
76 | - $fullSchema['examples'][$exampleKey] = is_array($example)? $example : json_decode($example, true); |
|
76 | + $fullSchema['examples'][$exampleKey] = is_array($example) ? $example : json_decode($example, true); |
|
77 | 77 | // pretty formatting of json example if decoded |
78 | 78 | } |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | 82 | |
83 | - if (!empty($fullSchema['examples'])) { |
|
83 | + if ( ! empty($fullSchema['examples'])) { |
|
84 | 84 | $this->description .= <<< HTML |
85 | 85 | <div> |
86 | 86 | Select Example: |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $outputValid = count($outputs) === 0; // back compatibility for handlers with no outputs defined |
105 | 105 | $outputValidatorErrors = []; |
106 | 106 | foreach ($outputs as $output) { |
107 | - if (!$output instanceof OutputInterface) { |
|
107 | + if ( ! $output instanceof OutputInterface) { |
|
108 | 108 | $outputValidatorErrors[] = ["Output does not implement OutputInterface"]; |
109 | 109 | continue; |
110 | 110 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | } |
116 | 116 | $outputValidatorErrors[] = $validationResult->getErrors(); |
117 | 117 | } |
118 | - if (!$outputValid) { |
|
118 | + if ( ! $outputValid) { |
|
119 | 119 | $response = $this->errorHandler->handleSchema($outputValidatorErrors, $params); |
120 | 120 | $code = $response->getCode(); |
121 | 121 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | private function checkAuth(ApiAuthorizationInterface $authorization, array $params): ?IResponse |
152 | 152 | { |
153 | 153 | try { |
154 | - if (!$authorization->authorized()) { |
|
154 | + if ( ! $authorization->authorized()) { |
|
155 | 155 | $response = $this->errorHandler->handleAuthorization($authorization, $params); |
156 | 156 | $this->response->setCode($response->getCode()); |
157 | 157 | return $response; |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | private function checkRateLimit(RateLimitInterface $rateLimit): ?IResponse |
168 | 168 | { |
169 | 169 | $rateLimitResponse = $rateLimit->check(); |
170 | - if (!$rateLimitResponse) { |
|
170 | + if ( ! $rateLimitResponse) { |
|
171 | 171 | return null; |
172 | 172 | } |
173 | 173 | |
@@ -175,12 +175,12 @@ discard block |
||
175 | 175 | $remaining = $rateLimitResponse->getRemaining(); |
176 | 176 | $retryAfter = $rateLimitResponse->getRetryAfter(); |
177 | 177 | |
178 | - $this->response->addHeader('X-RateLimit-Limit', (string)$limit); |
|
179 | - $this->response->addHeader('X-RateLimit-Remaining', (string)$remaining); |
|
178 | + $this->response->addHeader('X-RateLimit-Limit', (string) $limit); |
|
179 | + $this->response->addHeader('X-RateLimit-Remaining', (string) $remaining); |
|
180 | 180 | |
181 | 181 | if ($remaining === 0) { |
182 | 182 | $this->response->setCode(Response::S429_TOO_MANY_REQUESTS); |
183 | - $this->response->addHeader('Retry-After', (string)$retryAfter); |
|
183 | + $this->response->addHeader('Retry-After', (string) $retryAfter); |
|
184 | 184 | return $rateLimitResponse->getErrorResponse() ?: new JsonResponse(['status' => 'error', 'message' => 'Too many requests. Retry after ' . $retryAfter . ' seconds.']); |
185 | 185 | } |
186 | 186 | return null; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | |
243 | 243 | private function getRequestDomain(): ?string |
244 | 244 | { |
245 | - if (!filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
245 | + if ( ! filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
246 | 246 | return null; |
247 | 247 | } |
248 | 248 | $refererParsedUrl = parse_url(filter_input(INPUT_SERVER, 'HTTP_REFERER')); |
249 | - if (!(isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
249 | + if ( ! (isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
250 | 250 | return null; |
251 | 251 | } |
252 | 252 | $url = $refererParsedUrl['scheme'] . '://' . $refererParsedUrl['host']; |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | $data = [ |
159 | 159 | 'openapi' => '3.0.0', |
160 | 160 | 'info' => [ |
161 | - 'version' => (string)$version, |
|
161 | + 'version' => (string) $version, |
|
162 | 162 | 'title' => 'Nette API', |
163 | 163 | ], |
164 | 164 | 'servers' => [ |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | 'paths' => $this->getPaths($apis, $baseUrl, $basePath), |
218 | 218 | ]; |
219 | 219 | |
220 | - if (!$securitySchemes) { |
|
220 | + if ( ! $securitySchemes) { |
|
221 | 221 | unset($data['components']['securitySchemes']); |
222 | 222 | } |
223 | 223 | |
224 | - if (!empty($this->definitions)) { |
|
224 | + if ( ! empty($this->definitions)) { |
|
225 | 225 | $data['components']['schemas'] = array_merge($this->definitions, $data['components']['schemas']); |
226 | 226 | } |
227 | 227 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | |
236 | 236 | private function getApis(string $version): array |
237 | 237 | { |
238 | - return array_filter($this->apiDecider->getApis(), function (Api $api) use ($version) { |
|
238 | + return array_filter($this->apiDecider->getApis(), function(Api $api) use ($version) { |
|
239 | 239 | return $version === $api->getEndpoint()->getVersion(); |
240 | 240 | }); |
241 | 241 | } |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $path = str_replace([$baseUrl, $basePath], '', $this->apiLink->link($api->getEndpoint())); |
256 | 256 | $responses = []; |
257 | 257 | $endpointPath = str_replace('v' . $api->getEndpoint()->getVersion() . '/', '', $api->getEndpoint()->getUrl()); |
258 | - if (!$this->isPathAllowed($endpointPath, $api->getEndpoint()->getMethod())) { |
|
258 | + if ( ! $this->isPathAllowed($endpointPath, $api->getEndpoint()->getMethod())) { |
|
259 | 259 | continue; |
260 | 260 | } |
261 | 261 | |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $parameters = $this->createParamsList($handler); |
273 | 273 | $requestBody = $this->createRequestBody($handler); |
274 | 274 | |
275 | - if (!empty($parameters) || !empty($requestBody)) { |
|
275 | + if ( ! empty($parameters) || ! empty($requestBody)) { |
|
276 | 276 | $responses[IResponse::S400_BAD_REQUEST] = [ |
277 | 277 | 'description' => 'Bad request', |
278 | 278 | 'content' => [ |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | |
288 | 288 | $authorization = $api->getAuthorization(); |
289 | 289 | |
290 | - if (!$authorization instanceof NoAuthorization) { |
|
290 | + if ( ! $authorization instanceof NoAuthorization) { |
|
291 | 291 | $responses[IResponse::S403_FORBIDDEN] = [ |
292 | 292 | 'description' => 'Operation forbidden', |
293 | 293 | 'content' => [ |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | foreach ($handler->outputs() as $output) { |
315 | 315 | if ($output instanceof JsonOutput) { |
316 | 316 | $schema = $this->transformSchema(json_decode($output->getSchema(), true)); |
317 | - if (!isset($responses[$output->getCode()])) { |
|
317 | + if ( ! isset($responses[$output->getCode()])) { |
|
318 | 318 | $responses[$output->getCode()] = [ |
319 | 319 | 'description' => $output->getDescription(), |
320 | 320 | 'content' => [ |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | ], |
324 | 324 | ], |
325 | 325 | ]; |
326 | - if (!empty($examples = $output->getExamples())) { |
|
326 | + if ( ! empty($examples = $output->getExamples())) { |
|
327 | 327 | if (count($examples) === 1) { |
328 | 328 | $example = is_array($output->getExample()) ? $output->getExample() : json_decode($output->getExample(), true); |
329 | 329 | $responses[$output->getCode()]['content']['application/json; charset=utf-8']['example'] = $example; |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | } |
336 | 336 | } |
337 | 337 | } else { |
338 | - if (!isset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']['oneOf'])) { |
|
338 | + if ( ! isset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']['oneOf'])) { |
|
339 | 339 | $tmp = $responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']; |
340 | 340 | unset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']); |
341 | 341 | $responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema'] = [ |
@@ -362,11 +362,11 @@ discard block |
||
362 | 362 | } |
363 | 363 | } |
364 | 364 | |
365 | - if (!empty($parameters)) { |
|
365 | + if ( ! empty($parameters)) { |
|
366 | 366 | $settings['parameters'] = $parameters; |
367 | 367 | } |
368 | 368 | |
369 | - if (!empty($requestBody)) { |
|
369 | + if ( ! empty($requestBody)) { |
|
370 | 370 | $settings['requestBody'] = $requestBody; |
371 | 371 | } |
372 | 372 | |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | foreach ($handler->params() as $param) { |
531 | 531 | if ($param instanceof JsonInputParam) { |
532 | 532 | $schema = json_decode($param->getSchema(), true); |
533 | - if (!empty($examples = $param->getExamples())) { |
|
533 | + if ( ! empty($examples = $param->getExamples())) { |
|
534 | 534 | if (count($examples) === 1) { |
535 | 535 | $schema['example'] = is_array($param->getExample()) ? $param->getExample() : json_decode($param->getExample(), true); |
536 | 536 | } else { |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | $schema = [ |
554 | 554 | 'type' => 'string', |
555 | 555 | ]; |
556 | - if (!empty($examples = $param->getExamples())) { |
|
556 | + if ( ! empty($examples = $param->getExamples())) { |
|
557 | 557 | if (count($examples) === 1) { |
558 | 558 | $schema['example'] = $param->getExample(); |
559 | 559 | } else { |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | } |
623 | 623 | } |
624 | 624 | |
625 | - if (!empty($requestBody['properties'])) { |
|
625 | + if ( ! empty($requestBody['properties'])) { |
|
626 | 626 | $requestBodySchema = [ |
627 | 627 | 'type' => 'object', |
628 | 628 | 'properties' => $requestBody['properties'], |