@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * |
122 | 122 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
123 | 123 | */ |
124 | - public function __construct(HttpClient $http, OAuthStorageInterface $storage, SettingsContainerInterface $options){ |
|
124 | + public function __construct(HttpClient $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(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
136 | + if (!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'); |
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){ |
|
152 | + public function __get(string $name) { |
|
153 | 153 | |
154 | - if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL'], true)){ |
|
154 | + if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL'], true)) { |
|
155 | 155 | return null; |
156 | 156 | } |
157 | 157 | |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | */ |
205 | 205 | public function __call(string $name, array $arguments):ResponseInterface{ |
206 | 206 | |
207 | - if(!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)){ |
|
207 | + if (!$this->endpoints instanceof EndpointMapInterface || !$this->endpoints->__isset($name)) { |
|
208 | 208 | throw new ApiClientException('endpoint not found'); |
209 | 209 | } |
210 | 210 | |
@@ -217,21 +217,21 @@ discard block |
||
217 | 217 | $path_elements = $m['path_elements'] ?? []; |
218 | 218 | $params_in_url = count($path_elements); |
219 | 219 | $params = $arguments[$params_in_url] ?? []; |
220 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
220 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
221 | 221 | |
222 | - if($params_in_url > 0){ |
|
222 | + if ($params_in_url > 0) { |
|
223 | 223 | |
224 | - if(count($urlparams) < $params_in_url){ |
|
224 | + if (count($urlparams) < $params_in_url) { |
|
225 | 225 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
226 | 226 | } |
227 | 227 | |
228 | 228 | $endpoint = sprintf($endpoint, ...$urlparams); |
229 | 229 | } |
230 | 230 | |
231 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
231 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
232 | 232 | $body = $arguments[$params_in_url + 1] ?? $params; |
233 | 233 | |
234 | - if($params === $body){ |
|
234 | + if ($params === $body) { |
|
235 | 235 | $params = []; |
236 | 236 | } |
237 | 237 | |
@@ -278,32 +278,32 @@ discard block |
||
278 | 278 | $token = $this->storage->getAccessToken($this->serviceName); |
279 | 279 | |
280 | 280 | // attempt to refresh an expired token |
281 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
281 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
282 | 282 | $token = $this->refreshAccessToken($token); |
283 | 283 | } |
284 | 284 | |
285 | 285 | $request = $this->requestFactory |
286 | 286 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params)); |
287 | 287 | |
288 | - foreach(array_merge($this->apiHeaders, $headers) as $header => $value){ |
|
288 | + foreach (array_merge($this->apiHeaders, $headers) as $header => $value) { |
|
289 | 289 | $request = $request->withAddedHeader($header, $value); |
290 | 290 | } |
291 | 291 | |
292 | 292 | $request = $this->getRequestAuthorization($request, $token); |
293 | 293 | |
294 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
294 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
295 | 295 | $contentType = strtolower($request->getHeaderLine('content-type')); |
296 | 296 | |
297 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
297 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
298 | 298 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
299 | 299 | } |
300 | - elseif($contentType === 'application/json'){ |
|
300 | + elseif ($contentType === 'application/json') { |
|
301 | 301 | $body = $this->streamFactory->createStream(json_encode($body)); |
302 | 302 | } |
303 | 303 | |
304 | 304 | } |
305 | 305 | |
306 | - if($body instanceof StreamInterface){ |
|
306 | + if ($body instanceof StreamInterface) { |
|
307 | 307 | $request = $request->withBody($body); |
308 | 308 | } |
309 | 309 |