@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | * Implements an abstract OAuth provider with all methods required by the OAuthInterface. |
| 38 | 38 | * It also implements a magic getter that allows to access the properties listed below. |
| 39 | 39 | */ |
| 40 | -abstract class OAuthProvider implements OAuthInterface{ |
|
| 40 | +abstract class OAuthProvider implements OAuthInterface { |
|
| 41 | 41 | |
| 42 | 42 | protected const ALLOWED_PROPERTIES = [ |
| 43 | 43 | 'apiDocs', 'apiURL', 'applicationURL', 'serviceName', 'userRevokeURL' |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | ClientInterface $http, |
| 142 | 142 | OAuthOptions|SettingsContainerInterface $options, |
| 143 | 143 | LoggerInterface $logger = null |
| 144 | - ){ |
|
| 144 | + ) { |
|
| 145 | 145 | $this->http = $http; |
| 146 | 146 | $this->options = $options; |
| 147 | 147 | $this->logger = $logger ?? new NullLogger; |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | public function __get(string $name):mixed{ |
| 165 | 165 | |
| 166 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
| 166 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
| 167 | 167 | return $this->{$name}; |
| 168 | 168 | } |
| 169 | 169 | |
@@ -258,11 +258,11 @@ discard block |
||
| 258 | 258 | ):ResponseInterface{ |
| 259 | 259 | $request = $this->requestFactory->createRequest($method ?? 'GET', $this->getRequestURL($path, $params)); |
| 260 | 260 | |
| 261 | - foreach($this->getRequestHeaders($headers) as $header => $value){ |
|
| 261 | + foreach ($this->getRequestHeaders($headers) as $header => $value) { |
|
| 262 | 262 | $request = $request->withAddedHeader($header, $value); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if($body !== null){ |
|
| 265 | + if ($body !== null) { |
|
| 266 | 266 | $body = $this->getRequestBody($body, $request); |
| 267 | 267 | $request = $request |
| 268 | 268 | ->withBody($body) |
@@ -301,30 +301,30 @@ discard block |
||
| 301 | 301 | */ |
| 302 | 302 | protected function getRequestBody(StreamInterface|array|string $body, RequestInterface $request):StreamInterface{ |
| 303 | 303 | |
| 304 | - if($body instanceof StreamInterface){ |
|
| 304 | + if ($body instanceof StreamInterface) { |
|
| 305 | 305 | return $body; // @codeCoverageIgnore |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if(is_string($body)){ |
|
| 308 | + if (is_string($body)) { |
|
| 309 | 309 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
| 310 | 310 | return $this->streamFactory->createStream($body); |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | - if(is_array($body)){ |
|
| 313 | + if (is_array($body)) { |
|
| 314 | 314 | $body = $this->cleanBodyParams($body); |
| 315 | 315 | $contentType = strtolower($request->getHeaderLine('content-type')); |
| 316 | 316 | |
| 317 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
| 317 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
| 318 | 318 | return $this->streamFactory->createStream(QueryUtil::build($body, PHP_QUERY_RFC1738)); |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | - if(in_array($contentType, ['application/json', 'application/vnd.api+json'])){ |
|
| 321 | + if (in_array($contentType, ['application/json', 'application/vnd.api+json'])) { |
|
| 322 | 322 | return $this->streamFactory->createStream(json_encode($body)); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | - throw new ProviderException('invalid body/content-type'); // @codeCoverageIgnore |
|
| 327 | + throw new ProviderException('invalid body/content-type'); // @codeCoverageIgnore |
|
| 328 | 328 | } |
| 329 | 329 | |
| 330 | 330 | /** |
@@ -346,18 +346,18 @@ discard block |
||
| 346 | 346 | protected function getRequestTarget(string $uri):string{ |
| 347 | 347 | $parsedURL = QueryUtil::parseUrl($uri); |
| 348 | 348 | |
| 349 | - if(!isset($parsedURL['path'])){ |
|
| 349 | + if (!isset($parsedURL['path'])) { |
|
| 350 | 350 | throw new ProviderException('invalid path'); |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | // for some reason we were given a host name |
| 354 | - if(isset($parsedURL['host'])){ |
|
| 354 | + if (isset($parsedURL['host'])) { |
|
| 355 | 355 | $api = QueryUtil::parseUrl($this->apiURL); |
| 356 | 356 | $host = $api['host'] ?? null; |
| 357 | 357 | |
| 358 | 358 | // back out if it doesn't match |
| 359 | - if($parsedURL['host'] !== $host){ |
|
| 360 | - throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'] , $host)); |
|
| 359 | + if ($parsedURL['host'] !== $host) { |
|
| 360 | + throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'], $host)); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // we explicitly ignore any existing parameters here |
@@ -374,15 +374,15 @@ discard block |
||
| 374 | 374 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
| 375 | 375 | |
| 376 | 376 | // get authorization only if we request the provider API |
| 377 | - if(str_starts_with((string)$request->getUri(), $this->apiURL)){ |
|
| 377 | + if (str_starts_with((string)$request->getUri(), $this->apiURL)) { |
|
| 378 | 378 | $token = $this->storage->getAccessToken($this->serviceName); |
| 379 | 379 | |
| 380 | 380 | // attempt to refresh an expired token |
| 381 | - if( |
|
| 381 | + if ( |
|
| 382 | 382 | $this instanceof TokenRefresh |
| 383 | 383 | && $this->options->tokenAutoRefresh |
| 384 | 384 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
| 385 | - ){ |
|
| 385 | + ) { |
|
| 386 | 386 | $token = $this->refreshAccessToken($token); |
| 387 | 387 | } |
| 388 | 388 | |