@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth; |
14 | 14 | |
15 | -class OAuthException extends \Exception{} |
|
15 | +class OAuthException extends \Exception {} |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\OAuthException; |
16 | 16 | |
17 | -class ProviderException extends OAuthException{} |
|
17 | +class ProviderException extends OAuthException {} |
@@ -138,11 +138,9 @@ |
||
138 | 138 | |
139 | 139 | if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
140 | 140 | $this->expires = $this::EOL_NEVER_EXPIRES; |
141 | - } |
|
142 | - elseif($expires > $now){ |
|
141 | + } elseif($expires > $now){ |
|
143 | 142 | $this->expires = $expires; |
144 | - } |
|
145 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
143 | + } elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
146 | 144 | $this->expires = $now + $expires; |
147 | 145 | } |
148 | 146 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @property int $expires |
30 | 30 | * @property string $provider |
31 | 31 | */ |
32 | -class AccessToken extends SettingsContainerAbstract{ |
|
32 | +class AccessToken extends SettingsContainerAbstract { |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Denotes an unknown end of life time. |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * |
85 | 85 | * @param iterable|null $properties |
86 | 86 | */ |
87 | - public function __construct(iterable $properties = null){ |
|
87 | + public function __construct(iterable $properties = null) { |
|
88 | 88 | parent::__construct($properties); |
89 | 89 | |
90 | 90 | $this->setExpiry($this->expires); |
@@ -109,19 +109,19 @@ discard block |
||
109 | 109 | public function setExpiry(int $expires = null):AccessToken{ |
110 | 110 | $now = time(); |
111 | 111 | |
112 | - if($expires!== null){ |
|
112 | + if ($expires !== null) { |
|
113 | 113 | $expires = intval($expires); |
114 | 114 | } |
115 | 115 | |
116 | 116 | $this->expires = $this::EOL_UNKNOWN; |
117 | 117 | |
118 | - if($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES){ |
|
118 | + if ($expires === 0 || $expires === $this::EOL_NEVER_EXPIRES) { |
|
119 | 119 | $this->expires = $this::EOL_NEVER_EXPIRES; |
120 | 120 | } |
121 | - elseif($expires > $now){ |
|
121 | + elseif ($expires > $now) { |
|
122 | 122 | $this->expires = $expires; |
123 | 123 | } |
124 | - elseif($expires > 0 && $expires < $this::EXPIRY_MAX){ |
|
124 | + elseif ($expires > 0 && $expires < $this::EXPIRY_MAX) { |
|
125 | 125 | $this->expires = $now + $expires; |
126 | 126 | } |
127 | 127 |
@@ -14,4 +14,4 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\OAuthException; |
16 | 16 | |
17 | -class OAuthStorageException extends OAuthException{} |
|
17 | +class OAuthStorageException extends OAuthException {} |
@@ -78,11 +78,9 @@ |
||
78 | 78 | |
79 | 79 | if(!$data || !is_array($data)){ |
80 | 80 | throw new ProviderException('unable to parse token response'); |
81 | - } |
|
82 | - elseif(isset($data['error'])){ |
|
81 | + } elseif(isset($data['error'])){ |
|
83 | 82 | throw new ProviderException('error retrieving access token: '.$data['error']); |
84 | - } |
|
85 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
83 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
86 | 84 | throw new ProviderException('invalid token'); |
87 | 85 | } |
88 | 86 |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | implode, in_array, is_array, parse_str, parse_url, random_bytes, strtoupper; |
22 | 22 | use function chillerlan\HTTP\Psr7\{build_http_query, decompress_content, merge_query, r_rawurlencode}; |
23 | 23 | |
24 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
24 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @var string |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | ->withHeader('Accept-Encoding', 'identity') |
64 | 64 | ; |
65 | 65 | |
66 | - foreach($this->authHeaders as $header => $value){ |
|
66 | + foreach ($this->authHeaders as $header => $value) { |
|
67 | 67 | $request = $request->withAddedHeader($header, $value); |
68 | 68 | } |
69 | 69 | |
@@ -80,20 +80,20 @@ discard block |
||
80 | 80 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
81 | 81 | parse_str(decompress_content($response), $data); |
82 | 82 | |
83 | - if(!$data || !is_array($data)){ |
|
83 | + if (!$data || !is_array($data)) { |
|
84 | 84 | throw new ProviderException('unable to parse token response'); |
85 | 85 | } |
86 | - elseif(isset($data['error'])){ |
|
86 | + elseif (isset($data['error'])) { |
|
87 | 87 | throw new ProviderException('error retrieving access token: '.$data['error']); |
88 | 88 | } |
89 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
89 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
90 | 90 | throw new ProviderException('invalid token'); |
91 | 91 | } |
92 | 92 | |
93 | - if( |
|
93 | + if ( |
|
94 | 94 | $checkCallbackConfirmed |
95 | 95 | && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true') |
96 | - ){ |
|
96 | + ) { |
|
97 | 97 | throw new ProviderException('oauth callback unconfirmed'); |
98 | 98 | } |
99 | 99 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
141 | 141 | $parseURL = parse_url($url); |
142 | 142 | |
143 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
143 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
144 | 144 | throw new ProviderException('getSignature: invalid url'); |
145 | 145 | } |
146 | 146 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | |
149 | 149 | $signatureParams = array_merge($query, $params); |
150 | 150 | |
151 | - if(isset($signatureParams['oauth_signature'])){ |
|
151 | + if (isset($signatureParams['oauth_signature'])) { |
|
152 | 152 | unset($signatureParams['oauth_signature']); |
153 | 153 | } |
154 | 154 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $token->accessTokenSecret |
201 | 201 | ); |
202 | 202 | |
203 | - if(isset($query['oauth_session_handle'])){ |
|
203 | + if (isset($query['oauth_session_handle'])) { |
|
204 | 204 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
205 | 205 | } |
206 | 206 |
@@ -296,8 +296,7 @@ |
||
296 | 296 | // @todo: content type support |
297 | 297 | if($contentType === 'application/x-www-form-urlencoded'){ |
298 | 298 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
299 | - } |
|
300 | - elseif($contentType === 'application/json'){ |
|
299 | + } elseif($contentType === 'application/json'){ |
|
301 | 300 | $body = $this->streamFactory->createStream(json_encode($body)); |
302 | 301 | } |
303 | 302 |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @property string $serviceName |
40 | 40 | * @property string $userRevokeURL |
41 | 41 | */ |
42 | -abstract class OAuthProvider implements OAuthInterface{ |
|
42 | +abstract class OAuthProvider implements OAuthInterface { |
|
43 | 43 | use LoggerAwareTrait; |
44 | 44 | |
45 | 45 | protected const ALLOWED_PROPERTIES = [ |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | OAuthStorageInterface $storage, |
152 | 152 | SettingsContainerInterface $options, |
153 | 153 | LoggerInterface $logger = null |
154 | - ){ |
|
154 | + ) { |
|
155 | 155 | $this->http = $http; |
156 | 156 | $this->storage = $storage; |
157 | 157 | $this->options = $options; |
@@ -163,10 +163,10 @@ discard block |
||
163 | 163 | |
164 | 164 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
165 | 165 | |
166 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
166 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
167 | 167 | $this->endpoints = new $this->endpointMap; |
168 | 168 | |
169 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
169 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
170 | 170 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
171 | 171 | } |
172 | 172 | |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return mixed|null |
181 | 181 | */ |
182 | - public function __get(string $name){ |
|
182 | + public function __get(string $name) { |
|
183 | 183 | |
184 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
184 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
185 | 185 | return $this->{$name}; |
186 | 186 | } |
187 | 187 | |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | */ |
243 | 243 | public function __call(string $name, array $arguments):ResponseInterface{ |
244 | 244 | |
245 | - if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){ |
|
245 | + if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) { |
|
246 | 246 | throw new ApiClientException('MagicAPI not available'); |
247 | 247 | } |
248 | 248 | |
249 | - if(!$this->endpoints->__isset($name)){ |
|
249 | + if (!$this->endpoints->__isset($name)) { |
|
250 | 250 | throw new ApiClientException('endpoint not found: "'.$name.'"'); |
251 | 251 | } |
252 | 252 | |
@@ -259,21 +259,21 @@ discard block |
||
259 | 259 | $path_elements = $m['path_elements'] ?? []; |
260 | 260 | $params_in_url = count($path_elements); |
261 | 261 | $params = $arguments[$params_in_url] ?? []; |
262 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
262 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
263 | 263 | |
264 | - if($params_in_url > 0){ |
|
264 | + if ($params_in_url > 0) { |
|
265 | 265 | |
266 | - if(count($urlparams) < $params_in_url){ |
|
266 | + if (count($urlparams) < $params_in_url) { |
|
267 | 267 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
268 | 268 | } |
269 | 269 | |
270 | 270 | $endpoint = sprintf($endpoint, ...$urlparams); |
271 | 271 | } |
272 | 272 | |
273 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
273 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
274 | 274 | $body = $arguments[$params_in_url + 1] ?? $params; |
275 | 275 | |
276 | - if($params === $body){ |
|
276 | + if ($params === $body) { |
|
277 | 277 | $params = []; |
278 | 278 | } |
279 | 279 | |
@@ -323,24 +323,24 @@ discard block |
||
323 | 323 | $request = $this->requestFactory |
324 | 324 | ->createRequest($method ?? 'GET', merge_query($this->apiURL.$path, $params ?? [])); |
325 | 325 | |
326 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
326 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
327 | 327 | $request = $request->withAddedHeader($header, $value); |
328 | 328 | } |
329 | 329 | |
330 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
330 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
331 | 331 | $contentType = strtolower($request->getHeaderLine('content-type')); |
332 | 332 | |
333 | 333 | // @todo: content type support |
334 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
334 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
335 | 335 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
336 | 336 | } |
337 | - elseif($contentType === 'application/json'){ |
|
337 | + elseif ($contentType === 'application/json') { |
|
338 | 338 | $body = $this->streamFactory->createStream(json_encode($body)); |
339 | 339 | } |
340 | 340 | |
341 | 341 | } |
342 | 342 | |
343 | - if($body instanceof StreamInterface){ |
|
343 | + if ($body instanceof StreamInterface) { |
|
344 | 344 | $request = $request |
345 | 345 | ->withBody($body) |
346 | 346 | ->withHeader('Content-length', $body->getSize()) |
@@ -356,15 +356,15 @@ discard block |
||
356 | 356 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
357 | 357 | |
358 | 358 | // get authorization only if we request the provider API |
359 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
359 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
360 | 360 | $token = $this->storage->getAccessToken($this->serviceName); |
361 | 361 | |
362 | 362 | // attempt to refresh an expired token |
363 | - if( |
|
363 | + if ( |
|
364 | 364 | $this instanceof TokenRefresh |
365 | 365 | && $this->options->tokenAutoRefresh |
366 | 366 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
367 | - ){ |
|
367 | + ) { |
|
368 | 368 | $token = $this->refreshAccessToken($token); |
369 | 369 | } |
370 | 370 |
@@ -18,6 +18,6 @@ |
||
18 | 18 | * checkState(string $state = null):void |
19 | 19 | * setState(array $params):array |
20 | 20 | */ |
21 | -interface CSRFToken{ |
|
21 | +interface CSRFToken { |
|
22 | 22 | |
23 | 23 | } |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth; |
14 | 14 | |
15 | -trait OAuthOptionsTrait{ |
|
15 | +trait OAuthOptionsTrait { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * The application key (or id) given by your provider |
@@ -12,7 +12,7 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\OAuth\Core; |
14 | 14 | |
15 | -interface TokenRefresh{ |
|
15 | +interface TokenRefresh { |
|
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Tries to refresh an existing access token with an associated refresh token |