@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @property string $serviceName |
43 | 43 | * @property string|null $userRevokeURL |
44 | 44 | */ |
45 | -abstract class OAuthProvider implements OAuthInterface{ |
|
45 | +abstract class OAuthProvider implements OAuthInterface { |
|
46 | 46 | use LoggerAwareTrait; |
47 | 47 | |
48 | 48 | protected const ALLOWED_PROPERTIES = [ |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | OAuthStorageInterface $storage, |
157 | 157 | SettingsContainerInterface $options, |
158 | 158 | LoggerInterface $logger = null |
159 | - ){ |
|
159 | + ) { |
|
160 | 160 | $this->http = $http; |
161 | 161 | $this->storage = $storage; |
162 | 162 | $this->options = $options; |
@@ -170,10 +170,10 @@ discard block |
||
170 | 170 | |
171 | 171 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
172 | 172 | |
173 | - if(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
173 | + if (!empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
174 | 174 | $this->endpoints = new $this->endpointMap; |
175 | 175 | |
176 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
176 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
177 | 177 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
178 | 178 | } |
179 | 179 | |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return mixed|null |
190 | 190 | */ |
191 | - public function __get(string $name){ |
|
191 | + public function __get(string $name) { |
|
192 | 192 | |
193 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
193 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
194 | 194 | return $this->{$name}; |
195 | 195 | } |
196 | 196 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | */ |
249 | 249 | public function __call(string $endpointName, array $arguments):ResponseInterface{ |
250 | 250 | |
251 | - if(!$this->endpoints instanceof EndpointMap){ |
|
251 | + if (!$this->endpoints instanceof EndpointMap) { |
|
252 | 252 | throw new ApiClientException('MagicAPI not available'); // @codeCoverageIgnore |
253 | 253 | } |
254 | 254 | |
255 | - if(!isset($this->endpoints->{$endpointName})){ |
|
255 | + if (!isset($this->endpoints->{$endpointName})) { |
|
256 | 256 | throw new ApiClientException('endpoint not found: "'.$endpointName.'"'); |
257 | 257 | } |
258 | 258 | |
@@ -272,25 +272,25 @@ discard block |
||
272 | 272 | $path_element_count = count($path_elements); |
273 | 273 | $query_param_count = count($query_params); |
274 | 274 | |
275 | - if($path_element_count > 0){ |
|
275 | + if ($path_element_count > 0) { |
|
276 | 276 | $path = $this->parsePathElements($path, $path_elements, $path_element_count, $arguments); |
277 | 277 | } |
278 | 278 | |
279 | - if($query_param_count > 0){ |
|
279 | + if ($query_param_count > 0) { |
|
280 | 280 | // $params is the first argument after path segments |
281 | 281 | $params = $arguments[$path_element_count] ?? null; |
282 | 282 | |
283 | - if(is_array($params)){ |
|
283 | + if (is_array($params)) { |
|
284 | 284 | $params = $this->cleanQueryParams($this->removeUnlistedParams($params, $query_params)); |
285 | 285 | } |
286 | 286 | } |
287 | 287 | |
288 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body){ |
|
288 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body) { |
|
289 | 289 | // if no query params are present, $body is the first argument after any path segments |
290 | 290 | $argPos = $query_param_count > 0 ? 1 : 0; |
291 | 291 | $body = $arguments[$path_element_count + $argPos] ?? null; |
292 | 292 | |
293 | - if(is_array($body)){ |
|
293 | + if (is_array($body)) { |
|
294 | 294 | $body = $this->cleanBodyParams($body); |
295 | 295 | } |
296 | 296 | } |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | // we don't know if all of the given arguments are path elements... |
312 | 312 | $urlparams = array_slice($arguments, 0, $path_element_count); |
313 | 313 | |
314 | - if(count($urlparams) !== $path_element_count){ |
|
314 | + if (count($urlparams) !== $path_element_count) { |
|
315 | 315 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
316 | 316 | } |
317 | 317 | |
318 | - foreach($urlparams as $i => $param){ |
|
318 | + foreach ($urlparams as $i => $param) { |
|
319 | 319 | // ...but we do know that the arguments after the path elements are usually array or null |
320 | - if(!is_scalar($param)){ |
|
320 | + if (!is_scalar($param)) { |
|
321 | 321 | $msg = 'invalid path element value for "%s": %s'; |
322 | 322 | |
323 | 323 | throw new APIClientException(sprintf($msg, $path_elements[$i], var_export($param, true))); |
@@ -333,9 +333,9 @@ discard block |
||
333 | 333 | protected function removeUnlistedParams(array $params, array $allowed):array{ |
334 | 334 | $query = []; |
335 | 335 | // remove any params that are not listed |
336 | - foreach($params as $key => $value){ |
|
336 | + foreach ($params as $key => $value) { |
|
337 | 337 | |
338 | - if(!in_array($key, $allowed, true)){ |
|
338 | + if (!in_array($key, $allowed, true)) { |
|
339 | 339 | continue; |
340 | 340 | } |
341 | 341 | |
@@ -394,28 +394,28 @@ discard block |
||
394 | 394 | $request = $this->requestFactory |
395 | 395 | ->createRequest($method ?? 'GET', $this->mergeQuery($this->getRequestTarget($path), $params ?? [])); |
396 | 396 | |
397 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
397 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
398 | 398 | $request = $request->withAddedHeader($header, $value); |
399 | 399 | } |
400 | 400 | |
401 | - if($request->hasHeader('content-type')){ |
|
401 | + if ($request->hasHeader('content-type')) { |
|
402 | 402 | $contentType = strtolower($request->getHeaderLine('content-type')); |
403 | 403 | |
404 | - if(is_array($body)){ |
|
405 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
404 | + if (is_array($body)) { |
|
405 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
406 | 406 | $body = $this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738)); |
407 | 407 | } |
408 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
408 | + elseif ($contentType === 'application/json' || $contentType === 'application/vnd.api+json') { |
|
409 | 409 | $body = $this->streamFactory->createStream(json_encode($body)); |
410 | 410 | } |
411 | 411 | } |
412 | - elseif(is_string($body)){ |
|
412 | + elseif (is_string($body)) { |
|
413 | 413 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
414 | 414 | $body = $this->streamFactory->createStream($body); |
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
418 | - if($body instanceof StreamInterface){ |
|
418 | + if ($body instanceof StreamInterface) { |
|
419 | 419 | $request = $request |
420 | 420 | ->withBody($body) |
421 | 421 | ->withHeader('Content-length', (string)$body->getSize()) |
@@ -437,16 +437,16 @@ discard block |
||
437 | 437 | protected function getRequestTarget(string $uri):string{ |
438 | 438 | $parsedURL = parseUrl($uri); |
439 | 439 | |
440 | - if(!isset($parsedURL['path'])){ |
|
440 | + if (!isset($parsedURL['path'])) { |
|
441 | 441 | throw new ProviderException('invalid path'); |
442 | 442 | } |
443 | 443 | |
444 | 444 | // for some reason we were given a host name |
445 | - if(isset($parsedURL['host'])){ |
|
445 | + if (isset($parsedURL['host'])) { |
|
446 | 446 | |
447 | 447 | // back out if it doesn't match |
448 | 448 | /** @phan-suppress-next-line PhanTypeArraySuspiciousNullable - $this->>apiURL should always return a host */ |
449 | - if($parsedURL['host'] !== parseUrl($this->apiURL)['host']){ |
|
449 | + if ($parsedURL['host'] !== parseUrl($this->apiURL)['host']) { |
|
450 | 450 | throw new ProviderException('given host does not match provider host'); |
451 | 451 | } |
452 | 452 | |
@@ -464,15 +464,15 @@ discard block |
||
464 | 464 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
465 | 465 | |
466 | 466 | // get authorization only if we request the provider API |
467 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
467 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
468 | 468 | $token = $this->storage->getAccessToken($this->serviceName); |
469 | 469 | |
470 | 470 | // attempt to refresh an expired token |
471 | - if( |
|
471 | + if ( |
|
472 | 472 | $this instanceof TokenRefresh |
473 | 473 | && $this->options->tokenAutoRefresh |
474 | 474 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
475 | - ){ |
|
475 | + ) { |
|
476 | 476 | $token = $this->refreshAccessToken($token); |
477 | 477 | } |
478 | 478 |
@@ -404,12 +404,10 @@ |
||
404 | 404 | if(is_array($body)){ |
405 | 405 | if($contentType === 'application/x-www-form-urlencoded'){ |
406 | 406 | $body = $this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738)); |
407 | - } |
|
408 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
407 | + } elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
409 | 408 | $body = $this->streamFactory->createStream(json_encode($body)); |
410 | 409 | } |
411 | - } |
|
412 | - elseif(is_string($body)){ |
|
410 | + } elseif(is_string($body)){ |
|
413 | 411 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
414 | 412 | $body = $this->streamFactory->createStream($body); |
415 | 413 | } |
@@ -40,6 +40,6 @@ |
||
40 | 40 | * @property array $curl_multi_options |
41 | 41 | * @property bool $curl_check_OCSP |
42 | 42 | */ |
43 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
43 | +class OAuthOptions extends SettingsContainerAbstract { |
|
44 | 44 | use OAuthOptionsTrait, HTTPOptionsTrait; |
45 | 45 | } |