@@ -16,7 +16,7 @@ |
||
| 16 | 16 | |
| 17 | 17 | public function __construct(string $status, array $errors = []) |
| 18 | 18 | { |
| 19 | - if (!in_array($status, [self::STATUS_OK, self::STATUS_ERROR], true)) { |
|
| 19 | + if ( ! in_array($status, [self::STATUS_OK, self::STATUS_ERROR], true)) { |
|
| 20 | 20 | throw new InvalidArgumentException($status . ' is not valid validation result status'); |
| 21 | 21 | } |
| 22 | 22 | |
@@ -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()) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | $outputValidatorErrors[] = $validationResult->getErrors(); |
| 98 | 98 | } |
| 99 | - if (!$outputValid) { |
|
| 99 | + if ( ! $outputValid) { |
|
| 100 | 100 | $response = new JsonApiResponse(500, ['status' => 'error', 'message' => 'Internal server error', 'details' => $outputValidatorErrors]); |
| 101 | 101 | } |
| 102 | 102 | $code = $response->getCode(); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | private function checkAuth(ApiAuthorizationInterface $authorization): bool |
| 137 | 137 | { |
| 138 | - if (!$authorization->authorized()) { |
|
| 138 | + if ( ! $authorization->authorized()) { |
|
| 139 | 139 | $this->getHttpResponse()->setCode(Response::S403_FORBIDDEN); |
| 140 | 140 | $this->sendResponse(new JsonResponse(['status' => 'error', 'message' => $authorization->getErrorMessage()])); |
| 141 | 141 | return false; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | private function checkRateLimit(RateLimitInterface $rateLimit): bool |
| 147 | 147 | { |
| 148 | 148 | $rateLimitResponse = $rateLimit->check(); |
| 149 | - if (!$rateLimitResponse) { |
|
| 149 | + if ( ! $rateLimitResponse) { |
|
| 150 | 150 | return true; |
| 151 | 151 | } |
| 152 | 152 | |
@@ -154,12 +154,12 @@ discard block |
||
| 154 | 154 | $remaining = $rateLimitResponse->getRemaining(); |
| 155 | 155 | $retryAfter = $rateLimitResponse->getRetryAfter(); |
| 156 | 156 | |
| 157 | - $this->getHttpResponse()->addHeader('X-RateLimit-Limit', (string)$limit); |
|
| 158 | - $this->getHttpResponse()->addHeader('X-RateLimit-Remaining', (string)$remaining); |
|
| 157 | + $this->getHttpResponse()->addHeader('X-RateLimit-Limit', (string) $limit); |
|
| 158 | + $this->getHttpResponse()->addHeader('X-RateLimit-Remaining', (string) $remaining); |
|
| 159 | 159 | |
| 160 | 160 | if ($remaining === 0) { |
| 161 | 161 | $this->getHttpResponse()->setCode(Response::S429_TOO_MANY_REQUESTS); |
| 162 | - $this->getHttpResponse()->addHeader('Retry-After', (string)$retryAfter); |
|
| 162 | + $this->getHttpResponse()->addHeader('Retry-After', (string) $retryAfter); |
|
| 163 | 163 | $response = $rateLimitResponse->getErrorResponse() ?: new JsonResponse(['status' => 'error', 'message' => 'Too many requests. Retry after ' . $retryAfter . ' seconds.']); |
| 164 | 164 | $this->sendResponse($response); |
| 165 | 165 | return false; |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | |
| 240 | 240 | private function getRequestDomain(): ?string |
| 241 | 241 | { |
| 242 | - if (!filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
| 242 | + if ( ! filter_input(INPUT_SERVER, 'HTTP_REFERER')) { |
|
| 243 | 243 | return null; |
| 244 | 244 | } |
| 245 | 245 | $refererParsedUrl = parse_url(filter_input(INPUT_SERVER, 'HTTP_REFERER')); |
| 246 | - if (!(isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
| 246 | + if ( ! (isset($refererParsedUrl['scheme']) && isset($refererParsedUrl['host']))) { |
|
| 247 | 247 | return null; |
| 248 | 248 | } |
| 249 | 249 | $url = $refererParsedUrl['scheme'] . '://' . $refererParsedUrl['host']; |
@@ -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 | } |