@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | if (count($args) < 3) { |
| 31 | 31 | $message = "Invalid link destination, too few arguments."; |
| 32 | - if (!Debugger::$productionMode) { |
|
| 32 | + if ( ! Debugger::$productionMode) { |
|
| 33 | 33 | throw new InvalidLinkException($message); |
| 34 | 34 | } |
| 35 | 35 | Debugger::log($message, Debugger::EXCEPTION); |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | ]; |
| 46 | 46 | |
| 47 | 47 | return $writer->write('echo ($this->filters->apiLink)((new Tomaj\NetteApi\EndpointIdentifier(' . |
| 48 | - $arguments['method'] . ', ' . |
|
| 49 | - $arguments['version'] . ', ' . |
|
| 48 | + $arguments['method'] . ', ' . |
|
| 49 | + $arguments['version'] . ', ' . |
|
| 50 | 50 | $arguments['package'] . ', ' . |
| 51 | 51 | $arguments['action'] . ')), ' . $arguments['params'] . ')'); |
| 52 | 52 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | $paramsProcessor = new ParamsProcessor($handler->params()); |
| 84 | 84 | if ($paramsProcessor->isError()) { |
| 85 | 85 | $this->response->setCode(Response::S400_BAD_REQUEST); |
| 86 | - if (!Debugger::$productionMode) { |
|
| 86 | + if ( ! Debugger::$productionMode) { |
|
| 87 | 87 | $response = new JsonResponse(['status' => 'error', 'message' => 'wrong input', 'detail' => $paramsProcessor->getErrors()]); |
| 88 | 88 | } else { |
| 89 | 89 | $response = new JsonResponse(['status' => 'error', 'message' => 'wrong input']); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $outputValid = count($handler->outputs()) === 0; // back compatibility for handlers with no outputs defined |
| 98 | 98 | $outputValidatorErrors = []; |
| 99 | 99 | foreach ($handler->outputs() as $output) { |
| 100 | - if (!$output instanceof OutputInterface) { |
|
| 100 | + if ( ! $output instanceof OutputInterface) { |
|
| 101 | 101 | $outputValidatorErrors[] = ["Output does not implement OutputInterface"]; |
| 102 | 102 | continue; |
| 103 | 103 | } |
@@ -108,15 +108,15 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | $outputValidatorErrors[] = $validationResult->getErrors(); |
| 110 | 110 | } |
| 111 | - if (!$outputValid) { |
|
| 111 | + if ( ! $outputValid) { |
|
| 112 | 112 | Debugger::log($outputValidatorErrors, Debugger::ERROR); |
| 113 | - if (!Debugger::$productionMode) { |
|
| 113 | + if ( ! Debugger::$productionMode) { |
|
| 114 | 114 | $response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error', 'details' => $outputValidatorErrors]); |
| 115 | 115 | } |
| 116 | 116 | } |
| 117 | 117 | $code = $response->getCode(); |
| 118 | 118 | } catch (Throwable $exception) { |
| 119 | - if (!Debugger::$productionMode) { |
|
| 119 | + if ( ! Debugger::$productionMode) { |
|
| 120 | 120 | $response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error', 'detail' => $exception->getMessage()]); |
| 121 | 121 | } else { |
| 122 | 122 | $response = new JsonApiResponse(Response::S500_INTERNAL_SERVER_ERROR, ['status' => 'error', 'message' => 'Internal server error']); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | private function checkAuth(ApiAuthorizationInterface $authorization): ?IResponse |
| 152 | 152 | { |
| 153 | - if (!$authorization->authorized()) { |
|
| 153 | + if ( ! $authorization->authorized()) { |
|
| 154 | 154 | $this->response->setCode(Response::S403_FORBIDDEN); |
| 155 | 155 | return new JsonResponse(['status' => 'error', 'message' => $authorization->getErrorMessage()]); |
| 156 | 156 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | private function checkRateLimit(RateLimitInterface $rateLimit): ?IResponse |
| 161 | 161 | { |
| 162 | 162 | $rateLimitResponse = $rateLimit->check(); |
| 163 | - if (!$rateLimitResponse) { |
|
| 163 | + if ( ! $rateLimitResponse) { |
|
| 164 | 164 | return null; |
| 165 | 165 | } |
| 166 | 166 | |
@@ -168,12 +168,12 @@ discard block |
||
| 168 | 168 | $remaining = $rateLimitResponse->getRemaining(); |
| 169 | 169 | $retryAfter = $rateLimitResponse->getRetryAfter(); |
| 170 | 170 | |
| 171 | - $this->response->addHeader('X-RateLimit-Limit', (string)$limit); |
|
| 172 | - $this->response->addHeader('X-RateLimit-Remaining', (string)$remaining); |
|
| 171 | + $this->response->addHeader('X-RateLimit-Limit', (string) $limit); |
|
| 172 | + $this->response->addHeader('X-RateLimit-Remaining', (string) $remaining); |
|
| 173 | 173 | |
| 174 | 174 | if ($remaining === 0) { |
| 175 | 175 | $this->response->setCode(Response::S429_TOO_MANY_REQUESTS); |
| 176 | - $this->response->addHeader('Retry-After', (string)$retryAfter); |
|
| 176 | + $this->response->addHeader('Retry-After', (string) $retryAfter); |
|
| 177 | 177 | return $rateLimitResponse->getErrorResponse() ?: new JsonResponse(['status' => 'error', 'message' => 'Too many requests. Retry after ' . $retryAfter . ' seconds.']); |
| 178 | 178 | } |
| 179 | 179 | return null; |
@@ -235,11 +235,11 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | private function getRequestDomain(): ?string |
| 237 | 237 | { |
| 238 | - if (!filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
| 238 | + if ( ! filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
| 239 | 239 | return null; |
| 240 | 240 | } |
| 241 | 241 | $refererParsedUrl = parse_url(filter_input(INPUT_SERVER, 'HTTP_REFERER')); |
| 242 | - if (!(isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
| 242 | + if ( ! (isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
| 243 | 243 | return null; |
| 244 | 244 | } |
| 245 | 245 | $url = $refererParsedUrl['scheme'] . '://' . $refererParsedUrl['host']; |
@@ -46,11 +46,11 @@ |
||
| 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 | |
@@ -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(int $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' => [ |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | ] |
| 315 | 315 | ]; |
| 316 | 316 | } else { |
| 317 | - if (!isset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']['oneOf'])) { |
|
| 317 | + if ( ! isset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']['oneOf'])) { |
|
| 318 | 318 | $tmp = $responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']; |
| 319 | 319 | unset($responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema']); |
| 320 | 320 | $responses[$output->getCode()]['content']['application/json; charset=utf-8']['schema'] = [ |
@@ -341,11 +341,11 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if (!empty($parameters)) { |
|
| 344 | + if ( ! empty($parameters)) { |
|
| 345 | 345 | $settings['parameters'] = $parameters; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | - if (!empty($requestBody)) { |
|
| 348 | + if ( ! empty($requestBody)) { |
|
| 349 | 349 | $settings['requestBody'] = $requestBody; |
| 350 | 350 | } |
| 351 | 351 | |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | } |
| 559 | 559 | } |
| 560 | 560 | |
| 561 | - if (!empty($requestBody['properties'])) { |
|
| 561 | + if ( ! empty($requestBody['properties'])) { |
|
| 562 | 562 | $requestBodySchema = [ |
| 563 | 563 | 'type' => 'object', |
| 564 | 564 | 'properties' => $requestBody['properties'], |