@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | public function enableGlobalPreflight(CorsPreflightHandlerInterface $corsHandler = null) |
65 | 65 | { |
66 | - if (!$corsHandler) { |
|
66 | + if ( ! $corsHandler) { |
|
67 | 67 | $corsHandler = new CorsPreflightHandler(new Response()); |
68 | 68 | } |
69 | 69 | $this->globalPreflightHandler = $corsHandler; |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | private function getHandler(Api $api): ApiHandlerInterface |
103 | 103 | { |
104 | 104 | $handler = $api->getHandler(); |
105 | - if (!is_string($handler)) { |
|
105 | + if ( ! is_string($handler)) { |
|
106 | 106 | return $handler; |
107 | 107 | } |
108 | 108 |
@@ -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(), |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | $data = [ |
153 | 153 | 'openapi' => '3.0.0', |
154 | 154 | 'info' => [ |
155 | - 'version' => (string)$version, |
|
155 | + 'version' => (string) $version, |
|
156 | 156 | 'title' => 'Nette API', |
157 | 157 | ], |
158 | 158 | 'servers' => [ |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | 'paths' => $this->getPaths($apis, $baseUrl, $basePath), |
212 | 212 | ]; |
213 | 213 | |
214 | - if (!$securitySchemes) { |
|
214 | + if ( ! $securitySchemes) { |
|
215 | 215 | unset($data['components']['securitySchemes']); |
216 | 216 | } |
217 | 217 | |
218 | - if (!empty($this->definitions)) { |
|
218 | + if ( ! empty($this->definitions)) { |
|
219 | 219 | $data['components']['schemas'] = array_merge($this->definitions, $data['components']['schemas']); |
220 | 220 | } |
221 | 221 | |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | |
230 | 230 | private function getApis(string $version): array |
231 | 231 | { |
232 | - return array_filter($this->apiDecider->getApis(), function (Api $api) use ($version) { |
|
232 | + return array_filter($this->apiDecider->getApis(), function(Api $api) use ($version) { |
|
233 | 233 | return $version === $api->getEndpoint()->getVersion(); |
234 | 234 | }); |
235 | 235 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | $parameters = $this->createParamsList($handler); |
263 | 263 | $requestBody = $this->createRequestBody($handler); |
264 | 264 | |
265 | - if (!empty($parameters) || !empty($requestBody)) { |
|
265 | + if ( ! empty($parameters) || ! empty($requestBody)) { |
|
266 | 266 | $responses[IResponse::S400_BAD_REQUEST] = [ |
267 | 267 | 'description' => 'Bad request', |
268 | 268 | 'content' => [ |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | |
278 | 278 | $authorization = $api->getAuthorization(); |
279 | 279 | |
280 | - if (!$authorization instanceof NoAuthorization) { |
|
280 | + if ( ! $authorization instanceof NoAuthorization) { |
|
281 | 281 | $responses[IResponse::S403_FORBIDDEN] = [ |
282 | 282 | 'description' => 'Operation forbidden', |
283 | 283 | 'content' => [ |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | foreach ($handler->outputs() as $output) { |
305 | 305 | if ($output instanceof JsonOutput) { |
306 | 306 | $schema = $this->transformSchema(json_decode($output->getSchema(), true)); |
307 | - if (!isset($responses[$output->getCode()])) { |
|
307 | + if ( ! isset($responses[$output->getCode()])) { |
|
308 | 308 | $responses[$output->getCode()] = [ |
309 | 309 | 'description' => $output->getDescription(), |
310 | 310 | 'content' => [ |
@@ -313,19 +313,19 @@ discard block |
||
313 | 313 | ], |
314 | 314 | ] |
315 | 315 | ]; |
316 | - if (!empty($examples = $output->getExamples())) { |
|
316 | + if ( ! empty($examples = $output->getExamples())) { |
|
317 | 317 | if (count($examples) === 1) { |
318 | - $example = is_array($output->getExample())? $output->getExample() : json_decode($output->getExample(), true); |
|
318 | + $example = is_array($output->getExample()) ? $output->getExample() : json_decode($output->getExample(), true); |
|
319 | 319 | $responses[$output->getCode()]['content']['application/json; charset=utf-8']['example'] = $example; |
320 | 320 | } else { |
321 | 321 | foreach ($examples as $exampleKey => $example) { |
322 | - $example = is_array($example)? $example : json_decode($example, true); |
|
322 | + $example = is_array($example) ? $example : json_decode($example, true); |
|
323 | 323 | $responses[$output->getCode()]['content']['application/json; charset=utf-8']['examples'][$exampleKey] = $example; |
324 | 324 | } |
325 | 325 | } |
326 | 326 | } |
327 | 327 | } else { |
328 | - if (!isset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']['oneOf'])) { |
|
328 | + if ( ! isset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']['oneOf'])) { |
|
329 | 329 | $tmp = $responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']; |
330 | 330 | unset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']); |
331 | 331 | $responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema'] = [ |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | } |
353 | 353 | } |
354 | 354 | |
355 | - if (!empty($parameters)) { |
|
355 | + if ( ! empty($parameters)) { |
|
356 | 356 | $settings['parameters'] = $parameters; |
357 | 357 | } |
358 | 358 | |
359 | - if (!empty($requestBody)) { |
|
359 | + if ( ! empty($requestBody)) { |
|
360 | 360 | $settings['requestBody'] = $requestBody; |
361 | 361 | } |
362 | 362 | |
@@ -487,12 +487,12 @@ discard block |
||
487 | 487 | foreach ($handler->params() as $param) { |
488 | 488 | if ($param instanceof JsonInputParam) { |
489 | 489 | $schema = json_decode($param->getSchema(), true); |
490 | - if (!empty($examples = $param->getExamples())) { |
|
490 | + if ( ! empty($examples = $param->getExamples())) { |
|
491 | 491 | if (count($examples) === 1) { |
492 | - $schema['example'] = is_array($param->getExample())? $param->getExample() : json_decode($param->getExample(), true); |
|
492 | + $schema['example'] = is_array($param->getExample()) ? $param->getExample() : json_decode($param->getExample(), true); |
|
493 | 493 | } else { |
494 | 494 | foreach ($examples as $exampleKey => $example) { |
495 | - $schema['examples'][$exampleKey] = is_array($example)? $example : json_decode($example, true); |
|
495 | + $schema['examples'][$exampleKey] = is_array($example) ? $example : json_decode($example, true); |
|
496 | 496 | } |
497 | 497 | } |
498 | 498 | } |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | $schema = [ |
511 | 511 | 'type' => 'string', |
512 | 512 | ]; |
513 | - if (!empty($examples = $param->getExamples())) { |
|
513 | + if ( ! empty($examples = $param->getExamples())) { |
|
514 | 514 | if (count($examples) === 1) { |
515 | 515 | $schema['example'] = $param->getExample(); |
516 | 516 | } else { |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
582 | - if (!empty($requestBody['properties'])) { |
|
582 | + if ( ! empty($requestBody['properties'])) { |
|
583 | 583 | $requestBodySchema = [ |
584 | 584 | 'type' => 'object', |
585 | 585 | 'properties' => $requestBody['properties'], |
@@ -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']; |