@@ -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 |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | ->withHeader('Accept-Encoding', 'identity') |
| 66 | 66 | ; |
| 67 | 67 | |
| 68 | - foreach($this->authHeaders as $header => $value){ |
|
| 68 | + foreach ($this->authHeaders as $header => $value) { |
|
| 69 | 69 | $request = $request->withAddedHeader($header, $value); |
| 70 | 70 | } |
| 71 | 71 | |
@@ -82,17 +82,17 @@ discard block |
||
| 82 | 82 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
| 83 | 83 | parse_str(decompress_content($response), $data); |
| 84 | 84 | |
| 85 | - if(!$data || !is_array($data)){ |
|
| 85 | + if (!$data || !is_array($data)) { |
|
| 86 | 86 | throw new ProviderException('unable to parse token response'); |
| 87 | 87 | } |
| 88 | - elseif(isset($data['error'])){ |
|
| 88 | + elseif (isset($data['error'])) { |
|
| 89 | 89 | throw new ProviderException('error retrieving access token: '.$data['error']); |
| 90 | 90 | } |
| 91 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
| 91 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
| 92 | 92 | throw new ProviderException('invalid token'); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')){ |
|
| 95 | + if ($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')) { |
|
| 96 | 96 | throw new ProviderException('oauth callback unconfirmed'); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
| 139 | 139 | $parseURL = parse_url($url); |
| 140 | 140 | |
| 141 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
| 141 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
| 142 | 142 | throw new ProviderException('getSignature: invalid url'); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | $signatureParams = array_merge($query, $params); |
| 148 | 148 | |
| 149 | - if(isset($signatureParams['oauth_signature'])){ |
|
| 149 | + if (isset($signatureParams['oauth_signature'])) { |
|
| 150 | 150 | unset($signatureParams['oauth_signature']); |
| 151 | 151 | } |
| 152 | 152 | |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $token->accessTokenSecret |
| 205 | 205 | ); |
| 206 | 206 | |
| 207 | - if(isset($query['oauth_session_handle'])){ |
|
| 207 | + if (isset($query['oauth_session_handle'])) { |
|
| 208 | 208 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
| 209 | 209 | } |
| 210 | 210 | |
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | |
| 15 | 15 | use Psr\Http\Message\UriInterface; |
| 16 | 16 | |
| 17 | -interface OAuth2Interface extends OAuthInterface{ |
|
| 17 | +interface OAuth2Interface extends OAuthInterface { |
|
| 18 | 18 | |
| 19 | 19 | const HEADER_OAUTH = 0; |
| 20 | 20 | const HEADER_BEARER = 1; |
@@ -36,6 +36,6 @@ |
||
| 36 | 36 | * @property bool $ssl_verifypeer |
| 37 | 37 | * @property string $curlHandle |
| 38 | 38 | */ |
| 39 | -class OAuthOptions extends SettingsContainerAbstract{ |
|
| 39 | +class OAuthOptions extends SettingsContainerAbstract { |
|
| 40 | 40 | use OAuthOptionsTrait, HTTPOptionsTrait; |
| 41 | 41 | } |
@@ -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 | |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | * @property string $serviceName |
| 43 | 43 | * @property string $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 = [ |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | * |
| 150 | 150 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
| 151 | 151 | */ |
| 152 | - public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){ |
|
| 152 | + public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) { |
|
| 153 | 153 | $this->http = $http; |
| 154 | 154 | $this->storage = $storage; |
| 155 | 155 | $this->options = $options; |
@@ -161,10 +161,10 @@ discard block |
||
| 161 | 161 | |
| 162 | 162 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
| 163 | 163 | |
| 164 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
| 164 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
| 165 | 165 | $this->endpoints = new $this->endpointMap; |
| 166 | 166 | |
| 167 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
| 167 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
| 168 | 168 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
| 169 | 169 | } |
| 170 | 170 | |
@@ -177,9 +177,9 @@ discard block |
||
| 177 | 177 | * |
| 178 | 178 | * @return mixed|null |
| 179 | 179 | */ |
| 180 | - public function __get(string $name){ |
|
| 180 | + public function __get(string $name) { |
|
| 181 | 181 | |
| 182 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
| 182 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
| 183 | 183 | return $this->{$name}; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -248,11 +248,11 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | public function __call(string $name, array $arguments):ResponseInterface{ |
| 250 | 250 | |
| 251 | - if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){ |
|
| 251 | + if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) { |
|
| 252 | 252 | throw new ApiClientException('MagicAPI not available'); |
| 253 | 253 | } |
| 254 | 254 | |
| 255 | - if(!$this->endpoints->__isset($name)){ |
|
| 255 | + if (!$this->endpoints->__isset($name)) { |
|
| 256 | 256 | throw new ApiClientException('endpoint not found: "'.$name.'"'); |
| 257 | 257 | } |
| 258 | 258 | |
@@ -265,21 +265,21 @@ discard block |
||
| 265 | 265 | $path_elements = $m['path_elements'] ?? []; |
| 266 | 266 | $params_in_url = count($path_elements); |
| 267 | 267 | $params = $arguments[$params_in_url] ?? []; |
| 268 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
| 268 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
| 269 | 269 | |
| 270 | - if($params_in_url > 0){ |
|
| 270 | + if ($params_in_url > 0) { |
|
| 271 | 271 | |
| 272 | - if(count($urlparams) < $params_in_url){ |
|
| 272 | + if (count($urlparams) < $params_in_url) { |
|
| 273 | 273 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | $endpoint = sprintf($endpoint, ...$urlparams); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
| 279 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
| 280 | 280 | $body = $arguments[$params_in_url + 1] ?? $params; |
| 281 | 281 | |
| 282 | - if($params === $body){ |
|
| 282 | + if ($params === $body) { |
|
| 283 | 283 | $params = []; |
| 284 | 284 | } |
| 285 | 285 | |
@@ -329,24 +329,24 @@ discard block |
||
| 329 | 329 | $request = $this->requestFactory |
| 330 | 330 | ->createRequest($method ?? 'GET', merge_query($this->apiURL.$path, $params ?? [])); |
| 331 | 331 | |
| 332 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
| 332 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
| 333 | 333 | $request = $request->withAddedHeader($header, $value); |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
| 336 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
| 337 | 337 | $contentType = strtolower($request->getHeaderLine('content-type')); |
| 338 | 338 | |
| 339 | 339 | // @todo: content type support |
| 340 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
| 340 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
| 341 | 341 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
| 342 | 342 | } |
| 343 | - elseif($contentType === 'application/json'){ |
|
| 343 | + elseif ($contentType === 'application/json') { |
|
| 344 | 344 | $body = $this->streamFactory->createStream(json_encode($body)); |
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | } |
| 348 | 348 | |
| 349 | - if($body instanceof StreamInterface){ |
|
| 349 | + if ($body instanceof StreamInterface) { |
|
| 350 | 350 | $request = $request |
| 351 | 351 | ->withBody($body) |
| 352 | 352 | ->withHeader('Content-length', $body->getSize()) |
@@ -364,11 +364,11 @@ discard block |
||
| 364 | 364 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
| 365 | 365 | |
| 366 | 366 | // get authorization only if we request the provider API |
| 367 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
| 367 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
| 368 | 368 | $token = $this->storage->getAccessToken($this->serviceName); |
| 369 | 369 | |
| 370 | 370 | // attempt to refresh an expired token |
| 371 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
| 371 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
| 372 | 372 | $token = $this->refreshAccessToken($token); |
| 373 | 373 | } |
| 374 | 374 | |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | ]; |
| 35 | 35 | |
| 36 | 36 | /** @var \chillerlan\Settings\SettingsContainerInterface $options */ |
| 37 | -$options = new class($options_arr) extends OAuthOptions{ |
|
| 37 | +$options = new class($options_arr) extends OAuthOptions { |
|
| 38 | 38 | protected $sleep; // testHTTPClient |
| 39 | 39 | }; |
| 40 | 40 | |