@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | use Exception; |
14 | 14 | |
15 | -class OAuthException extends Exception{ |
|
15 | +class OAuthException extends Exception { |
|
16 | 16 | |
17 | 17 | } |
@@ -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); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function __get(string $name):mixed{ |
164 | 164 | |
165 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
165 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
166 | 166 | return $this->{$name}; |
167 | 167 | } |
168 | 168 | |
@@ -257,11 +257,11 @@ discard block |
||
257 | 257 | ):ResponseInterface{ |
258 | 258 | $request = $this->requestFactory->createRequest(($method ?? 'GET'), $this->getRequestURL($path, $params)); |
259 | 259 | |
260 | - foreach($this->getRequestHeaders($headers) as $header => $value){ |
|
260 | + foreach ($this->getRequestHeaders($headers) as $header => $value) { |
|
261 | 261 | $request = $request->withAddedHeader($header, $value); |
262 | 262 | } |
263 | 263 | |
264 | - if($body !== null){ |
|
264 | + if ($body !== null) { |
|
265 | 265 | $body = $this->getRequestBody($body, $request); |
266 | 266 | $request = $request |
267 | 267 | ->withBody($body) |
@@ -300,30 +300,30 @@ discard block |
||
300 | 300 | */ |
301 | 301 | protected function getRequestBody(StreamInterface|array|string $body, RequestInterface $request):StreamInterface{ |
302 | 302 | |
303 | - if($body instanceof StreamInterface){ |
|
303 | + if ($body instanceof StreamInterface) { |
|
304 | 304 | return $body; // @codeCoverageIgnore |
305 | 305 | } |
306 | 306 | |
307 | - if(is_string($body)){ |
|
307 | + if (is_string($body)) { |
|
308 | 308 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
309 | 309 | return $this->streamFactory->createStream($body); |
310 | 310 | } |
311 | 311 | |
312 | - if(is_array($body)){ |
|
312 | + if (is_array($body)) { |
|
313 | 313 | $body = $this->cleanBodyParams($body); |
314 | 314 | $contentType = strtolower($request->getHeaderLine('content-type')); |
315 | 315 | |
316 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
316 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
317 | 317 | return $this->streamFactory->createStream(QueryUtil::build($body, PHP_QUERY_RFC1738)); |
318 | 318 | } |
319 | 319 | |
320 | - if(in_array($contentType, ['application/json', 'application/vnd.api+json'])){ |
|
320 | + if (in_array($contentType, ['application/json', 'application/vnd.api+json'])) { |
|
321 | 321 | return $this->streamFactory->createStream(json_encode($body)); |
322 | 322 | } |
323 | 323 | |
324 | 324 | } |
325 | 325 | |
326 | - throw new ProviderException('invalid body/content-type'); // @codeCoverageIgnore |
|
326 | + throw new ProviderException('invalid body/content-type'); // @codeCoverageIgnore |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
@@ -345,18 +345,18 @@ discard block |
||
345 | 345 | protected function getRequestTarget(string $uri):string{ |
346 | 346 | $parsedURL = QueryUtil::parseUrl($uri); |
347 | 347 | |
348 | - if(!isset($parsedURL['path'])){ |
|
348 | + if (!isset($parsedURL['path'])) { |
|
349 | 349 | throw new ProviderException('invalid path'); |
350 | 350 | } |
351 | 351 | |
352 | 352 | // for some reason we were given a host name |
353 | - if(isset($parsedURL['host'])){ |
|
353 | + if (isset($parsedURL['host'])) { |
|
354 | 354 | $api = QueryUtil::parseUrl($this->apiURL); |
355 | 355 | $host = ($api['host'] ?? null); |
356 | 356 | |
357 | 357 | // back out if it doesn't match |
358 | - if($parsedURL['host'] !== $host){ |
|
359 | - throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'] , $host)); |
|
358 | + if ($parsedURL['host'] !== $host) { |
|
359 | + throw new ProviderException(sprintf('given host (%s) does not match provider (%s)', $parsedURL['host'], $host)); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | // we explicitly ignore any existing parameters here |
@@ -373,15 +373,15 @@ discard block |
||
373 | 373 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
374 | 374 | |
375 | 375 | // get authorization only if we request the provider API |
376 | - if(str_starts_with((string)$request->getUri(), $this->apiURL)){ |
|
376 | + if (str_starts_with((string)$request->getUri(), $this->apiURL)) { |
|
377 | 377 | $token = $this->storage->getAccessToken($this->serviceName); |
378 | 378 | |
379 | 379 | // attempt to refresh an expired token |
380 | - if( |
|
380 | + if ( |
|
381 | 381 | $this instanceof TokenRefresh |
382 | 382 | && $this->options->tokenAutoRefresh |
383 | 383 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
384 | - ){ |
|
384 | + ) { |
|
385 | 385 | $token = $this->refreshAccessToken($token); |
386 | 386 | } |
387 | 387 |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | use chillerlan\OAuth\OAuthException; |
14 | 14 | |
15 | -class ProviderException extends OAuthException{ |
|
15 | +class ProviderException extends OAuthException { |
|
16 | 16 | |
17 | 17 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @property int $expires |
31 | 31 | * @property string $provider |
32 | 32 | */ |
33 | -final class AccessToken extends SettingsContainerAbstract{ |
|
33 | +final class AccessToken extends SettingsContainerAbstract { |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Denotes an unknown end of lifetime. |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * |
92 | 92 | * @param iterable|null $properties |
93 | 93 | */ |
94 | - public function __construct(iterable $properties = null){ |
|
94 | + public function __construct(iterable $properties = null) { |
|
95 | 95 | parent::__construct($properties); |
96 | 96 | |
97 | 97 | $this->setExpiry($this->expires); |
@@ -114,16 +114,16 @@ discard block |
||
114 | 114 | public function setExpiry(int $expires = null):AccessToken{ |
115 | 115 | $now = time(); |
116 | 116 | |
117 | - if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
|
117 | + if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) { |
|
118 | 118 | $this->expires = $this::EOL_NEVER_EXPIRES; |
119 | 119 | } |
120 | - elseif($expires > $now){ |
|
120 | + elseif ($expires > $now) { |
|
121 | 121 | $this->expires = $expires; |
122 | 122 | } |
123 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
123 | + elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) { |
|
124 | 124 | $this->expires = ($now + $expires); |
125 | 125 | } |
126 | - else{ |
|
126 | + else { |
|
127 | 127 | $this->expires = $this::EOL_UNKNOWN; |
128 | 128 | } |
129 | 129 |
@@ -116,14 +116,11 @@ |
||
116 | 116 | |
117 | 117 | if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
118 | 118 | $this->expires = $this::EOL_NEVER_EXPIRES; |
119 | - } |
|
120 | - elseif($expires > $now){ |
|
119 | + } elseif($expires > $now){ |
|
121 | 120 | $this->expires = $expires; |
122 | - } |
|
123 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
121 | + } elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
124 | 122 | $this->expires = ($now + $expires); |
125 | - } |
|
126 | - else{ |
|
123 | + } else{ |
|
127 | 124 | $this->expires = $this::EOL_UNKNOWN; |
128 | 125 | } |
129 | 126 |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Implements an abstract OAuth1 provider with all methods required by the OAuth1Interface. |
30 | 30 | */ |
31 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
31 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * The request OAuth1 token URL |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | ->withHeader('Content-Length', '0') // tumblr requires a content-length header set |
68 | 68 | ; |
69 | 69 | |
70 | - foreach($this->authHeaders as $header => $value){ |
|
70 | + foreach ($this->authHeaders as $header => $value) { |
|
71 | 71 | $request = $request->withAddedHeader($header, $value); |
72 | 72 | } |
73 | 73 | |
@@ -84,20 +84,20 @@ discard block |
||
84 | 84 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
85 | 85 | $data = QueryUtil::parse(MessageUtil::decompress($response)); |
86 | 86 | |
87 | - if(empty($data)){ |
|
87 | + if (empty($data)) { |
|
88 | 88 | throw new ProviderException('unable to parse token response'); |
89 | 89 | } |
90 | - elseif(isset($data['error'])){ |
|
90 | + elseif (isset($data['error'])) { |
|
91 | 91 | throw new ProviderException('error retrieving access token: '.$data['error']); |
92 | 92 | } |
93 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
93 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
94 | 94 | throw new ProviderException('invalid token'); |
95 | 95 | } |
96 | 96 | |
97 | - if( |
|
97 | + if ( |
|
98 | 98 | $checkCallbackConfirmed |
99 | 99 | && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') |
100 | - ){ |
|
100 | + ) { |
|
101 | 101 | throw new ProviderException('oauth callback unconfirmed'); |
102 | 102 | } |
103 | 103 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
134 | 134 | $parsed = QueryUtil::parseUrl($url); |
135 | 135 | |
136 | - if(!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)){ |
|
136 | + if (!isset($parsed['host']) || !isset($parsed['scheme']) || !in_array($parsed['scheme'], ['http', 'https'], true)) { |
|
137 | 137 | throw new ProviderException('getSignature: invalid url'); |
138 | 138 | } |
139 | 139 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ]); |
151 | 151 | |
152 | 152 | // https://tools.ietf.org/html/rfc5849#section-3.4.2 |
153 | - $key = array_map('rawurlencode', [ |
|
153 | + $key = array_map('rawurlencode', [ |
|
154 | 154 | $this->options->secret, |
155 | 155 | ($accessTokenSecret ?? ''), |
156 | 156 | ]); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | $token->accessTokenSecret |
198 | 198 | ); |
199 | 199 | |
200 | - if(isset($query['oauth_session_handle'])){ |
|
200 | + if (isset($query['oauth_session_handle'])) { |
|
201 | 201 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
202 | 202 | } |
203 | 203 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | /** |
16 | 16 | * Specifies the basic methods for an OAuth2 provider. |
17 | 17 | */ |
18 | -interface OAuth2Interface extends OAuthInterface{ |
|
18 | +interface OAuth2Interface extends OAuthInterface { |
|
19 | 19 | |
20 | 20 | public const AUTH_METHOD_HEADER = 1; |
21 | 21 | public const AUTH_METHOD_QUERY = 2; |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * Implements an abstract OAuth storage adapter |
21 | 21 | */ |
22 | -abstract class OAuthStorageAbstract implements OAuthStorageInterface{ |
|
22 | +abstract class OAuthStorageAbstract implements OAuthStorageInterface { |
|
23 | 23 | use LoggerAwareTrait; |
24 | 24 | |
25 | 25 | protected OAuthOptions|SettingsContainerInterface $options; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * OAuthStorageAbstract constructor. |
30 | 30 | */ |
31 | - public function __construct(OAuthOptions|SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
31 | + public function __construct(OAuthOptions|SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
32 | 32 | $this->options = ($options ?? new OAuthOptions); |
33 | 33 | $this->logger = ($logger ?? new NullLogger); |
34 | 34 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | public function setServiceName(string $service):OAuthStorageInterface{ |
40 | 40 | $service = trim($service); |
41 | 41 | |
42 | - if(empty($service)){ |
|
42 | + if (empty($service)) { |
|
43 | 43 | throw new OAuthStorageException('service name must not be empty'); |
44 | 44 | } |
45 | 45 | |
@@ -53,13 +53,13 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function getServiceName(string $service = null):string{ |
55 | 55 | |
56 | - if($service === null && !isset($this->serviceName)){ |
|
56 | + if ($service === null && !isset($this->serviceName)) { |
|
57 | 57 | throw new OAuthStorageException('invalid service'); |
58 | 58 | } |
59 | 59 | |
60 | 60 | $name = trim($service ?? $this->serviceName); |
61 | 61 | |
62 | - if(empty($name)){ |
|
62 | + if (empty($name)) { |
|
63 | 63 | throw new OAuthStorageException('service name must not be empty'); |
64 | 64 | } |
65 | 65 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | */ |
80 | 80 | public function fromStorage(mixed $data):AccessToken{ |
81 | 81 | |
82 | - if(!is_string($data)){ |
|
82 | + if (!is_string($data)) { |
|
83 | 83 | throw new OAuthStorageException('invalid data'); |
84 | 84 | } |
85 | 85 |
@@ -12,6 +12,6 @@ |
||
12 | 12 | |
13 | 13 | use chillerlan\OAuth\OAuthException; |
14 | 14 | |
15 | -class OAuthStorageException extends OAuthException{ |
|
15 | +class OAuthStorageException extends OAuthException { |
|
16 | 16 | |
17 | 17 | } |