@@ -90,7 +90,7 @@ |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | $body = $response->getBody(); |
93 | - while(!$body->eof()) { |
|
93 | + while (!$body->eof()) { |
|
94 | 94 | echo $body->read(1024); |
95 | 95 | } |
96 | 96 | } |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | * @param MIMEProvider|null $MIMEProvider |
34 | 34 | * @throws InvalidRegexPatternException |
35 | 35 | */ |
36 | - public function __construct(string $pattern, ?MIMEProvider $MIMEProvider = null) |
|
36 | + public function __construct(string $pattern, ? MIMEProvider $MIMEProvider = null) |
|
37 | 37 | { |
38 | 38 | $this->pattern = $pattern; |
39 | 39 | |
40 | - if(@preg_match($pattern, null) === false) { |
|
40 | + if (@preg_match($pattern, null) === false) { |
|
41 | 41 | throw new InvalidRegexPatternException("Unable to parse regex pattern", preg_last_error()); |
42 | 42 | } |
43 | 43 | $this->MIMEProvider = $MIMEProvider; |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | public function parse(UriInterface $uri): ParsedURL |
54 | 54 | { |
55 | 55 | $matches = []; |
56 | - if(preg_match($this->pattern, $uri->getPath(), $matches) === 0) { |
|
56 | + if (preg_match($this->pattern, $uri->getPath(), $matches) === 0) { |
|
57 | 57 | throw new InvalidRequestURLException("Unable to parse request path: did not match regex"); |
58 | 58 | } |
59 | - if(!($endpoint = $matches["endpoint"] ?? null)) { |
|
59 | + if (!($endpoint = $matches["endpoint"] ?? null)) { |
|
60 | 60 | throw new InvalidRequestURLException("Unable to match endpoint in url"); |
61 | 61 | } |
62 | 62 | $element = $matches["element"] ?? null; |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | $apiKey = $matches["apiKey"] ?? null; |
65 | 65 | |
66 | 66 | $acceptableMimeTypes = []; |
67 | - if(($acceptableExtension = $matches["acceptableExtension"] ?? null)) { |
|
68 | - if(!$this->MIMEProvider) { |
|
67 | + if (($acceptableExtension = $matches["acceptableExtension"] ?? null)) { |
|
68 | + if (!$this->MIMEProvider) { |
|
69 | 69 | throw new UnableToParseURLException("Unable to accept acceptable extensions"); |
70 | 70 | } else { |
71 | 71 | try { |
@@ -18,9 +18,9 @@ |
||
18 | 18 | public function __construct(Configuration $config, string $namespace, string $configKey = 'keys') |
19 | 19 | { |
20 | 20 | $keys = []; |
21 | - if($config->has($configKey, $namespace)){ |
|
21 | + if ($config->has($configKey, $namespace)) { |
|
22 | 22 | $configKeys = $config->get($configKey, $namespace); |
23 | - if(is_array($configKeys)) { |
|
23 | + if (is_array($configKeys)) { |
|
24 | 24 | $keys = $configKeys; |
25 | 25 | } |
26 | 26 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | public function findKey(string $key): KeyMeta |
33 | 33 | { |
34 | - if($this->hasKey($key)) { |
|
34 | + if ($this->hasKey($key)) { |
|
35 | 35 | return new KeyMeta($key); |
36 | 36 | } else { |
37 | 37 | throw new UnableToFindKeyException("Unable to find API key in array."); |
@@ -28,11 +28,11 @@ discard block |
||
28 | 28 | |
29 | 29 | protected function handleServerException(UnableToHandleRequestException $exception, ResponseInterface $response): ResponseInterface |
30 | 30 | { |
31 | - if($exception instanceof InvalidRequestException) { |
|
31 | + if ($exception instanceof InvalidRequestException) { |
|
32 | 32 | $this->logCaughtThrowableResultingInHTTPCode(400, $exception, LogLevel::INFO); |
33 | 33 | return $response->withStatus(400, "Bad Request"); |
34 | 34 | |
35 | - } elseif( |
|
35 | + } elseif ( |
|
36 | 36 | $exception instanceof ElementNotFoundException || |
37 | 37 | $exception instanceof UnsupportedMethodException || |
38 | 38 | $exception instanceof UnableToCreateEndpointException |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | $this->logCaughtThrowableResultingInHTTPCode(404, $exception, LogLevel::INFO); |
41 | 41 | return $response->withStatus(404, "Not Found"); |
42 | 42 | |
43 | - } elseif($exception instanceof ElementConflictException) { |
|
43 | + } elseif ($exception instanceof ElementConflictException) { |
|
44 | 44 | $this->logCaughtThrowableResultingInHTTPCode(409, $exception, LogLevel::NOTICE); |
45 | 45 | return $response->withStatus(409, "Conflict"); |
46 | 46 | |
47 | - } elseif( |
|
47 | + } elseif ( |
|
48 | 48 | $exception instanceof MethodNotFoundException || |
49 | 49 | $exception instanceof EndpointExecutionException |
50 | 50 | ) { |
@@ -39,19 +39,19 @@ |
||
39 | 39 | */ |
40 | 40 | protected function handleServerException(UnableToHandleRequestException $exception, ResponseInterface $response): ResponseInterface |
41 | 41 | { |
42 | - if($exception instanceof InvalidAPIKeyException || $exception instanceof AccessDeniedException) { |
|
42 | + if ($exception instanceof InvalidAPIKeyException || $exception instanceof AccessDeniedException) { |
|
43 | 43 | $this->logCaughtThrowableResultingInHTTPCode(403, $exception, LogLevel::NOTICE); |
44 | 44 | return $response->withStatus(403, "Access Denied"); |
45 | 45 | |
46 | - } elseif($exception instanceof ThrottleLimitExceededException) { |
|
46 | + } elseif ($exception instanceof ThrottleLimitExceededException) { |
|
47 | 47 | $this->logCaughtThrowableResultingInHTTPCode(429, $exception, LogLevel::WARNING); |
48 | 48 | return $response->withStatus(429, "Too Many Requests"); |
49 | 49 | |
50 | - } elseif($exception instanceof NotAcceptableResponseTypeException) { |
|
50 | + } elseif ($exception instanceof NotAcceptableResponseTypeException) { |
|
51 | 51 | $this->logCaughtThrowableResultingInHTTPCode(406, $exception, LogLevel::INFO); |
52 | 52 | return $response->withStatus(406, "Not Acceptable"); |
53 | 53 | |
54 | - } elseif( |
|
54 | + } elseif ( |
|
55 | 55 | $exception instanceof UnableToCreateAPIResponseException || |
56 | 56 | $exception instanceof UnableToRouteRequestException |
57 | 57 | ) { |
@@ -52,7 +52,7 @@ |
||
52 | 52 | */ |
53 | 53 | private static function checkRequestDataIsArray($requestData): void |
54 | 54 | { |
55 | - if(!is_array($requestData)) { |
|
55 | + if (!is_array($requestData)) { |
|
56 | 56 | throw new UnableToCreateResourceParametersException("Unable to read request as array or null"); |
57 | 57 | } |
58 | 58 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @return APIResponseData |
16 | 16 | * @throws UnableToCreateAPIResponseDataException |
17 | 17 | */ |
18 | - abstract public function toAPIResponseData(?Resource $resource): APIResponseData; |
|
18 | + abstract public function toAPIResponseData(? Resource $resource) : APIResponseData; |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Uses above method for each resource, extracting the data into an array, creating a new APIResponseData from that array. |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | * @return APIResponseData |
24 | 24 | * @throws UnableToCreateAPIResponseDataException |
25 | 25 | */ |
26 | - public function multipleToAPIResponseData(?array $resources): APIResponseData |
|
26 | + public function multipleToAPIResponseData(? array $resources) : APIResponseData |
|
27 | 27 | { |
28 | - if(is_null($resources)) { |
|
28 | + if (is_null($resources)) { |
|
29 | 29 | return $this->toAPIResponseData(null); |
30 | 30 | } |
31 | 31 |
@@ -382,7 +382,7 @@ discard block |
||
382 | 382 | * @throws ElementNotFoundException |
383 | 383 | * @throws InvalidRequestException |
384 | 384 | */ |
385 | - abstract protected function deleteResource(ResourceParameters $parameters): ?Resource; |
|
385 | + abstract protected function deleteResource(ResourceParameters $parameters): ? Resource; |
|
386 | 386 | |
387 | 387 | /** |
388 | 388 | * @param ResourceParameters $parameters |
@@ -392,6 +392,6 @@ discard block |
||
392 | 392 | * @throws ElementNotFoundException |
393 | 393 | * @throws InvalidRequestException |
394 | 394 | */ |
395 | - abstract protected function deleteResources(ResourceParameters $parameters): ?array; |
|
395 | + abstract protected function deleteResources(ResourceParameters $parameters): ? array; |
|
396 | 396 | |
397 | 397 | } |