@@ -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: |
@@ -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::S401_Unauthorized] = [ |
| 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'], |
@@ -23,9 +23,9 @@ |
||
| 23 | 23 | \Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector::class, |
| 24 | 24 | \Rector\EarlyReturn\Rector\StmtsAwareInterface\ReturnEarlyIfVariableRector::class, |
| 25 | 25 | ]) |
| 26 | - ->withSets([ |
|
| 27 | - LevelSetList::UP_TO_PHP_71, |
|
| 28 | - SetList::DEAD_CODE, |
|
| 29 | - SetList::CODING_STYLE, |
|
| 30 | - SetList::EARLY_RETURN, |
|
| 31 | - ]); |
|
| 32 | 26 | \ No newline at end of file |
| 27 | + ->withSets([ |
|
| 28 | + LevelSetList::UP_TO_PHP_71, |
|
| 29 | + SetList::DEAD_CODE, |
|
| 30 | + SetList::CODING_STYLE, |
|
| 31 | + SetList::EARLY_RETURN, |
|
| 32 | + ]); |
|
| 33 | 33 | \ No newline at end of file |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $outputValid = count($outputs) === 0; // back compatibility for handlers with no outputs defined |
| 104 | 104 | $outputValidatorErrors = []; |
| 105 | 105 | foreach ($outputs as $output) { |
| 106 | - if (!$output instanceof OutputInterface) { |
|
| 106 | + if ( ! $output instanceof OutputInterface) { |
|
| 107 | 107 | $outputValidatorErrors[] = ["Output does not implement OutputInterface"]; |
| 108 | 108 | continue; |
| 109 | 109 | } |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $outputValidatorErrors[] = $validationResult->getErrors(); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if (!$outputValid) { |
|
| 120 | + if ( ! $outputValid) { |
|
| 121 | 121 | $response = $this->errorHandler->handleSchema($outputValidatorErrors, $params); |
| 122 | 122 | $code = $response->getCode(); |
| 123 | 123 | } |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | private function checkAuth(ApiAuthorizationInterface $authorization, array $params): ?IResponse |
| 154 | 154 | { |
| 155 | 155 | try { |
| 156 | - if (!$authorization->authorized()) { |
|
| 156 | + if ( ! $authorization->authorized()) { |
|
| 157 | 157 | $response = $this->errorHandler->handleAuthorization($authorization, $params); |
| 158 | 158 | $this->response->setCode($response->getCode()); |
| 159 | 159 | return $response; |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | private function checkRateLimit(RateLimitInterface $rateLimit): ?IResponse |
| 171 | 171 | { |
| 172 | 172 | $rateLimitResponse = $rateLimit->check(); |
| 173 | - if (!$rateLimitResponse) { |
|
| 173 | + if ( ! $rateLimitResponse) { |
|
| 174 | 174 | return null; |
| 175 | 175 | } |
| 176 | 176 | |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | $remaining = $rateLimitResponse->getRemaining(); |
| 179 | 179 | $retryAfter = $rateLimitResponse->getRetryAfter(); |
| 180 | 180 | |
| 181 | - $this->response->addHeader('X-RateLimit-Limit', (string)$limit); |
|
| 182 | - $this->response->addHeader('X-RateLimit-Remaining', (string)$remaining); |
|
| 181 | + $this->response->addHeader('X-RateLimit-Limit', (string) $limit); |
|
| 182 | + $this->response->addHeader('X-RateLimit-Remaining', (string) $remaining); |
|
| 183 | 183 | |
| 184 | 184 | if ($remaining === 0) { |
| 185 | 185 | $this->response->setCode(Response::S429_TOO_MANY_REQUESTS); |
| 186 | - $this->response->addHeader('Retry-After', (string)$retryAfter); |
|
| 186 | + $this->response->addHeader('Retry-After', (string) $retryAfter); |
|
| 187 | 187 | return $rateLimitResponse->getErrorResponse() ?: new JsonResponse(['status' => 'error', 'message' => 'Too many requests. Retry after ' . $retryAfter . ' seconds.']); |
| 188 | 188 | } |
| 189 | 189 | |
@@ -247,12 +247,12 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | private function getRequestDomain(): ?string |
| 249 | 249 | { |
| 250 | - if (!filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
| 250 | + if ( ! filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
| 251 | 251 | return null; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | $refererParsedUrl = parse_url(filter_input(INPUT_SERVER, 'HTTP_REFERER')); |
| 255 | - if (!(isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
| 255 | + if ( ! (isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
| 256 | 256 | return null; |
| 257 | 257 | } |
| 258 | 258 | |
@@ -22,7 +22,7 @@ |
||
| 22 | 22 | |
| 23 | 23 | public function validate(ResponseInterface $response): ValidationResultInterface |
| 24 | 24 | { |
| 25 | - if (!$response instanceof JsonApiResponse) { |
|
| 25 | + if ( ! $response instanceof JsonApiResponse) { |
|
| 26 | 26 | return new ValidationResult(ValidationResult::STATUS_ERROR); |
| 27 | 27 | } |
| 28 | 28 | |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | { |
| 14 | 14 | public function validate(ResponseInterface $response): ValidationResultInterface |
| 15 | 15 | { |
| 16 | - if (!$response instanceof RedirectResponse) { |
|
| 16 | + if ( ! $response instanceof RedirectResponse) { |
|
| 17 | 17 | return new ValidationResult(ValidationResult::STATUS_ERROR); |
| 18 | 18 | } |
| 19 | 19 | |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | { |
| 31 | 31 | $urlScript = $this->httpRequest->getUrl(); |
| 32 | 32 | $authentication = $this->authentications[$urlScript->getUser()] ?? null; |
| 33 | - if (!$authentication) { |
|
| 33 | + if ( ! $authentication) { |
|
| 34 | 34 | return false; |
| 35 | 35 | } |
| 36 | 36 | |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | $result = $this->tokenRepository->validToken($token); |
| 44 | - if (!$result) { |
|
| 44 | + if ( ! $result) { |
|
| 45 | 45 | $this->errorMessage = 'Token doesn\'t exists or isn\'t active'; |
| 46 | 46 | return false; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - if (!$this->isValidIp($this->tokenRepository->ipRestrictions($token))) { |
|
| 49 | + if ( ! $this->isValidIp($this->tokenRepository->ipRestrictions($token))) { |
|
| 50 | 50 | $this->errorMessage = 'Invalid IP'; |
| 51 | 51 | return false; |
| 52 | 52 | } |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | [$range, $netmask] = explode('/', $range, 2); |
| 110 | 110 | $range_decimal = ip2long($range); |
| 111 | 111 | $ipDecimal = ip2long($ip); |
| 112 | - $wildcard_decimal = 2 ** (32 - (int)$netmask) - 1; |
|
| 112 | + $wildcard_decimal = 2 ** (32 - (int) $netmask) - 1; |
|
| 113 | 113 | $netmask_decimal = ~ $wildcard_decimal; |
| 114 | 114 | return (($ipDecimal & $netmask_decimal) === ($range_decimal & $netmask_decimal)); |
| 115 | 115 | } |