@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
123 | 123 | */ |
124 | - public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options){ |
|
124 | + public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options) { |
|
125 | 125 | $this->http = $http; |
126 | 126 | $this->storage = $storage; |
127 | 127 | $this->options = $options; |
@@ -133,10 +133,10 @@ discard block |
||
133 | 133 | |
134 | 134 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
135 | 135 | |
136 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
136 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
137 | 137 | $this->endpoints = new $this->endpointMap; |
138 | 138 | |
139 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
139 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
140 | 140 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
141 | 141 | } |
142 | 142 | |
@@ -149,9 +149,9 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return string|null |
151 | 151 | */ |
152 | - public function __get(string $name):?string{ |
|
152 | + public function __get(string $name): ?string{ |
|
153 | 153 | |
154 | - if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)){ |
|
154 | + if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)) { |
|
155 | 155 | return null; |
156 | 156 | } |
157 | 157 | |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | */ |
208 | 208 | public function __call(string $name, array $arguments):ResponseInterface{ |
209 | 209 | |
210 | - if(!$this instanceof ApiClientInterface){ |
|
210 | + if (!$this instanceof ApiClientInterface) { |
|
211 | 211 | throw new ApiClientException('MagicAPI not available'); |
212 | 212 | } |
213 | 213 | |
214 | - if(!$this->endpoints->__isset($name)){ |
|
214 | + if (!$this->endpoints->__isset($name)) { |
|
215 | 215 | throw new ApiClientException('endpoint not found'); |
216 | 216 | } |
217 | 217 | |
@@ -224,21 +224,21 @@ discard block |
||
224 | 224 | $path_elements = $m['path_elements'] ?? []; |
225 | 225 | $params_in_url = count($path_elements); |
226 | 226 | $params = $arguments[$params_in_url] ?? []; |
227 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
227 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
228 | 228 | |
229 | - if($params_in_url > 0){ |
|
229 | + if ($params_in_url > 0) { |
|
230 | 230 | |
231 | - if(count($urlparams) < $params_in_url){ |
|
231 | + if (count($urlparams) < $params_in_url) { |
|
232 | 232 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
233 | 233 | } |
234 | 234 | |
235 | 235 | $endpoint = sprintf($endpoint, ...$urlparams); |
236 | 236 | } |
237 | 237 | |
238 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
238 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
239 | 239 | $body = $arguments[$params_in_url + 1] ?? $params; |
240 | 240 | |
241 | - if($params === $body){ |
|
241 | + if ($params === $body) { |
|
242 | 242 | $params = []; |
243 | 243 | } |
244 | 244 | |
@@ -285,32 +285,32 @@ discard block |
||
285 | 285 | $token = $this->storage->getAccessToken($this->serviceName); |
286 | 286 | |
287 | 287 | // attempt to refresh an expired token |
288 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
288 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
289 | 289 | $token = $this->refreshAccessToken($token); |
290 | 290 | } |
291 | 291 | |
292 | 292 | $request = $this->requestFactory |
293 | 293 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? [])); |
294 | 294 | |
295 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
295 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
296 | 296 | $request = $request->withAddedHeader($header, $value); |
297 | 297 | } |
298 | 298 | |
299 | 299 | $request = $this->getRequestAuthorization($request, $token); |
300 | 300 | |
301 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
301 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
302 | 302 | $contentType = strtolower($request->getHeaderLine('content-type')); |
303 | 303 | |
304 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
304 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
305 | 305 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
306 | 306 | } |
307 | - elseif($contentType === 'application/json'){ |
|
307 | + elseif ($contentType === 'application/json') { |
|
308 | 308 | $body = $this->streamFactory->createStream(json_encode($body)); |
309 | 309 | } |
310 | 310 | |
311 | 311 | } |
312 | 312 | |
313 | - if($body instanceof StreamInterface){ |
|
313 | + if ($body instanceof StreamInterface) { |
|
314 | 314 | $request = $request->withBody($body); |
315 | 315 | } |
316 | 316 |