@@ -21,11 +21,11 @@ |
||
21 | 21 | { |
22 | 22 | foreach ($this->params as $param) { |
23 | 23 | $validationResult = $param->validate(); |
24 | - if (!$validationResult->isOk()) { |
|
24 | + if ( ! $validationResult->isOk()) { |
|
25 | 25 | $this->errors[$param->getKey()] = $validationResult->getErrors(); |
26 | 26 | } |
27 | 27 | } |
28 | - return !empty($this->errors); |
|
28 | + return ! empty($this->errors); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function getErrors(): array |
@@ -40,7 +40,7 @@ |
||
40 | 40 | return new ValidationResult(ValidationResult::STATUS_ERROR, [json_last_error_msg()]); |
41 | 41 | } |
42 | 42 | |
43 | - if (!$value && $this->isRequired() === self::OPTIONAL) { |
|
43 | + if ( ! $value && $this->isRequired() === self::OPTIONAL) { |
|
44 | 44 | return new ValidationResult(ValidationResult::STATUS_OK); |
45 | 45 | } |
46 | 46 |
@@ -25,7 +25,7 @@ |
||
25 | 25 | |
26 | 26 | public function validate(ResponseInterface $response): ValidationResultInterface |
27 | 27 | { |
28 | - if (!$response instanceof JsonApiResponse) { |
|
28 | + if ( ! $response instanceof JsonApiResponse) { |
|
29 | 29 | return new ValidationResult(ValidationResult::STATUS_ERROR); |
30 | 30 | } |
31 | 31 | if ($this->code !== $response->getCode()) { |
@@ -205,7 +205,7 @@ |
||
205 | 205 | { |
206 | 206 | $result = []; |
207 | 207 | foreach ($values as $key => $value) { |
208 | - if (!is_array($value)) { |
|
208 | + if ( ! is_array($value)) { |
|
209 | 209 | $result[$key] = $value; |
210 | 210 | continue; |
211 | 211 | } |
@@ -11,7 +11,7 @@ |
||
11 | 11 | { |
12 | 12 | public function validate(ResponseInterface $response): ValidationResultInterface |
13 | 13 | { |
14 | - if (!$response instanceof RedirectResponse) { |
|
14 | + if ( ! $response instanceof RedirectResponse) { |
|
15 | 15 | return new ValidationResult(ValidationResult::STATUS_ERROR); |
16 | 16 | } |
17 | 17 | if ($this->code !== $response->getCode()) { |
@@ -294,6 +294,9 @@ discard block |
||
294 | 294 | return rtrim(str_replace($baseUrl, '', $basePath), '/'); |
295 | 295 | } |
296 | 296 | |
297 | + /** |
|
298 | + * @param string $path2 |
|
299 | + */ |
|
297 | 300 | private function getLongestCommonSubstring($path1, $path2) |
298 | 301 | { |
299 | 302 | if ($path1 === null) { |
@@ -436,6 +439,9 @@ discard block |
||
436 | 439 | return null; |
437 | 440 | } |
438 | 441 | |
442 | + /** |
|
443 | + * @param string $type |
|
444 | + */ |
|
439 | 445 | private function createIn($type) |
440 | 446 | { |
441 | 447 | if ($type == InputParam::TYPE_GET) { |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | $data = [ |
148 | 148 | 'openapi' => '3.0.0', |
149 | 149 | 'info' => [ |
150 | - 'version' => (string)$version, |
|
150 | + 'version' => (string) $version, |
|
151 | 151 | 'title' => 'Nette API', |
152 | 152 | ], |
153 | 153 | 'servers' => [ |
@@ -206,11 +206,11 @@ discard block |
||
206 | 206 | 'paths' => $this->getPaths($apis, $baseUrl, $basePath), |
207 | 207 | ]; |
208 | 208 | |
209 | - if (!$securitySchemes) { |
|
209 | + if ( ! $securitySchemes) { |
|
210 | 210 | unset($data['components']['securitySchemes']); |
211 | 211 | } |
212 | 212 | |
213 | - if (!empty($this->definitions)) { |
|
213 | + if ( ! empty($this->definitions)) { |
|
214 | 214 | $data['components']['schemas'] = array_merge($this->definitions, $data['components']['schemas']); |
215 | 215 | } |
216 | 216 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | |
225 | 225 | private function getApis(int $version): array |
226 | 226 | { |
227 | - return array_filter($this->apiDecider->getApis(), function (Api $api) use ($version) { |
|
227 | + return array_filter($this->apiDecider->getApis(), function(Api $api) use ($version) { |
|
228 | 228 | return $version === $api->getEndpoint()->getVersion(); |
229 | 229 | }); |
230 | 230 | } |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | } |
316 | 316 | |
317 | 317 | $parameters = $this->createParamsList($handler); |
318 | - if (!empty($parameters)) { |
|
318 | + if ( ! empty($parameters)) { |
|
319 | 319 | $settings['parameters'] = $parameters; |
320 | 320 | } |
321 | 321 | |
322 | 322 | $requestBody = $this->createRequestBody($handler); |
323 | - if (!empty($requestBody)) { |
|
323 | + if ( ! empty($requestBody)) { |
|
324 | 324 | $settings['requestBody'] = $requestBody; |
325 | 325 | } |
326 | 326 | |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | - if (!empty($postParams['properties'])) { |
|
492 | + if ( ! empty($postParams['properties'])) { |
|
493 | 493 | $postParamsSchema = [ |
494 | 494 | 'type' => 'object', |
495 | 495 | 'properties' => $postParams['properties'], |
@@ -29,7 +29,7 @@ |
||
29 | 29 | { |
30 | 30 | $urlScript = $this->httpRequest->getUrl(); |
31 | 31 | $authentication = $this->authentications[$urlScript->getUser()] ?? null; |
32 | - if (!$authentication) { |
|
32 | + if ( ! $authentication) { |
|
33 | 33 | return false; |
34 | 34 | } |
35 | 35 | return $authentication === $urlScript->getPassword(); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $paramsProcessor = new ParamsProcessor($handler->params()); |
83 | 83 | if ($paramsProcessor->isError()) { |
84 | 84 | $this->response->setCode(Response::S400_BAD_REQUEST); |
85 | - if (!Debugger::$productionMode) { |
|
85 | + if ( ! Debugger::$productionMode) { |
|
86 | 86 | $response = new JsonResponse(['status' => 'error', 'message' => 'wrong input', 'detail' => $paramsProcessor->getErrors()]); |
87 | 87 | } else { |
88 | 88 | $response = new JsonResponse(['status' => 'error', 'message' => 'wrong input']); |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | } |
104 | 104 | $outputValidatorErrors[] = $validationResult->getErrors(); |
105 | 105 | } |
106 | - if (!$outputValid) { |
|
106 | + if ( ! $outputValid) { |
|
107 | 107 | $response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error', 'details' => $outputValidatorErrors]); |
108 | 108 | } |
109 | 109 | $code = $response->getCode(); |
110 | 110 | } catch (Throwable $exception) { |
111 | - if (!Debugger::$productionMode) { |
|
111 | + if ( ! Debugger::$productionMode) { |
|
112 | 112 | $response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error', 'detail' => $exception->getMessage()]); |
113 | 113 | } else { |
114 | 114 | $response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error']); |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | |
143 | 143 | private function checkAuth(ApiAuthorizationInterface $authorization): ?IResponse |
144 | 144 | { |
145 | - if (!$authorization->authorized()) { |
|
145 | + if ( ! $authorization->authorized()) { |
|
146 | 146 | $this->response->setCode(Response::S403_FORBIDDEN); |
147 | 147 | return new JsonResponse(['status' => 'error', 'message' => $authorization->getErrorMessage()]); |
148 | 148 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | private function checkRateLimit(RateLimitInterface $rateLimit): ?IResponse |
153 | 153 | { |
154 | 154 | $rateLimitResponse = $rateLimit->check(); |
155 | - if (!$rateLimitResponse) { |
|
155 | + if ( ! $rateLimitResponse) { |
|
156 | 156 | return null; |
157 | 157 | } |
158 | 158 | |
@@ -160,12 +160,12 @@ discard block |
||
160 | 160 | $remaining = $rateLimitResponse->getRemaining(); |
161 | 161 | $retryAfter = $rateLimitResponse->getRetryAfter(); |
162 | 162 | |
163 | - $this->response->addHeader('X-RateLimit-Limit', (string)$limit); |
|
164 | - $this->response->addHeader('X-RateLimit-Remaining', (string)$remaining); |
|
163 | + $this->response->addHeader('X-RateLimit-Limit', (string) $limit); |
|
164 | + $this->response->addHeader('X-RateLimit-Remaining', (string) $remaining); |
|
165 | 165 | |
166 | 166 | if ($remaining === 0) { |
167 | 167 | $this->response->setCode(Response::S429_TOO_MANY_REQUESTS); |
168 | - $this->response->addHeader('Retry-After', (string)$retryAfter); |
|
168 | + $this->response->addHeader('Retry-After', (string) $retryAfter); |
|
169 | 169 | return $rateLimitResponse->getErrorResponse() ?: new JsonResponse(['status' => 'error', 'message' => 'Too many requests. Retry after ' . $retryAfter . ' seconds.']); |
170 | 170 | } |
171 | 171 | return null; |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | |
228 | 228 | private function getRequestDomain(): ?string |
229 | 229 | { |
230 | - if (!filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
230 | + if ( ! filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
231 | 231 | return null; |
232 | 232 | } |
233 | 233 | $refererParsedUrl = parse_url(filter_input(INPUT_SERVER, 'HTTP_REFERER')); |
234 | - if (!(isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
234 | + if ( ! (isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
235 | 235 | return null; |
236 | 236 | } |
237 | 237 | $url = $refererParsedUrl['scheme'] . '://' . $refererParsedUrl['host']; |
@@ -20,7 +20,7 @@ |
||
20 | 20 | protected function readAuthorizationToken(): ?string |
21 | 21 | { |
22 | 22 | $apiKey = $_COOKIE[$this->cookieName] ?? null; |
23 | - if (!$apiKey) { |
|
23 | + if ( ! $apiKey) { |
|
24 | 24 | $this->errorMessage = 'API key is not set'; |
25 | 25 | return null; |
26 | 26 | } |