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