@@ -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']; |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | /** |
| 51 | 51 | * Transform data using Fractal |
| 52 | 52 | */ |
| 53 | - protected function transform(Item|Collection $resource): array |
|
| 53 | + protected function transform(Item | Collection $resource): array |
|
| 54 | 54 | { |
| 55 | 55 | return $this->fractal->createData($resource)->toArray(); |
| 56 | 56 | } |
@@ -91,12 +91,12 @@ |
||
| 91 | 91 | $errors = []; |
| 92 | 92 | |
| 93 | 93 | // Check if any endpoints are invalid |
| 94 | - if (array_any($endpoints, static fn($endpoint) => !$endpoint instanceof \Tomaj\NetteApi\EndpointInterface)) { |
|
| 94 | + if (array_any($endpoints, static fn($endpoint) => ! $endpoint instanceof \Tomaj\NetteApi\EndpointInterface)) { |
|
| 95 | 95 | $errors[] = 'Some endpoints do not implement EndpointInterface'; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | // Check if all endpoints have valid methods |
| 99 | - if (!array_all($endpoints, static fn($endpoint) => in_array($endpoint->getMethod(), ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], true))) { |
|
| 99 | + if ( ! array_all($endpoints, static fn($endpoint) => in_array($endpoint->getMethod(), ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], true))) { |
|
| 100 | 100 | $errors[] = 'Some endpoints have invalid HTTP methods'; |
| 101 | 101 | } |
| 102 | 102 | |
@@ -25,10 +25,10 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function __construct( |
| 27 | 27 | public readonly int $code, |
| 28 | - public readonly array|JsonSerializable $payload, |
|
| 28 | + public readonly array | JsonSerializable $payload, |
|
| 29 | 29 | string $contentType = 'application/json', |
| 30 | 30 | public readonly string $charset = 'utf-8', |
| 31 | - public readonly DateTimeInterface|null|false $expiration = null |
|
| 31 | + public readonly DateTimeInterface | null | false $expiration = null |
|
| 32 | 32 | ) { |
| 33 | 33 | $this->contentType = $contentType; |
| 34 | 34 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | return $this->code; |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | - public function getPayload(): array|JsonSerializable |
|
| 41 | + public function getPayload(): array | JsonSerializable |
|
| 42 | 42 | { |
| 43 | 43 | return $this->payload; |
| 44 | 44 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function __construct( |
| 19 | 19 | public readonly EndpointInterface $endpoint, |
| 20 | - public readonly ApiHandlerInterface|string $handler, |
|
| 20 | + public readonly ApiHandlerInterface | string $handler, |
|
| 21 | 21 | public readonly ApiAuthorizationInterface $authorization, |
| 22 | 22 | ?RateLimitInterface $rateLimit = null |
| 23 | 23 | ) { |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | return $this->endpoint; |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - public function getHandler(): ApiHandlerInterface|string |
|
| 32 | + public function getHandler(): ApiHandlerInterface | string |
|
| 33 | 33 | { |
| 34 | 34 | return $this->handler; |
| 35 | 35 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | public function __construct( |
| 30 | 30 | string $method, |
| 31 | - string|int $version, |
|
| 31 | + string | int $version, |
|
| 32 | 32 | public readonly string $package, |
| 33 | 33 | public readonly ?string $apiAction = null |
| 34 | 34 | ) { |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function addApi( |
| 88 | 88 | EndpointInterface $endpointIdentifier, |
| 89 | - ApiHandlerInterface|string $handler, |
|
| 89 | + ApiHandlerInterface | string $handler, |
|
| 90 | 90 | ApiAuthorizationInterface $apiAuthorization, |
| 91 | 91 | ?RateLimitInterface $rateLimit = null |
| 92 | 92 | ): self { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $handler = $this->container->getByType($handler); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - if (!$handler instanceof ApiHandlerInterface) { |
|
| 161 | + if ( ! $handler instanceof ApiHandlerInterface) { |
|
| 162 | 162 | throw new \InvalidArgumentException('Handler must implement ApiHandlerInterface'); |
| 163 | 163 | } |
| 164 | 164 | |