@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\Core\OAuth1Provider; |
16 | 16 | |
17 | -class OAuth1Testprovider extends OAuth1Provider{ |
|
17 | +class OAuth1Testprovider extends OAuth1Provider { |
|
18 | 18 | |
19 | 19 | protected $apiURL = 'https://api.example.com'; |
20 | 20 | protected $requestTokenURL = 'https://example.com/oauth/request_token'; |
@@ -14,7 +14,7 @@ |
||
14 | 14 | |
15 | 15 | use chillerlan\HTTP\MagicAPI\EndpointMap; |
16 | 16 | |
17 | -class TestEndpoints extends EndpointMap{ |
|
17 | +class TestEndpoints extends EndpointMap { |
|
18 | 18 | |
19 | 19 | protected $test = [ |
20 | 20 | 'path' => '/test/%1$s', |
@@ -24,7 +24,7 @@ |
||
24 | 24 | protected $authURL = 'https://example.com/oauth2/authorize'; |
25 | 25 | protected $accessTokenURL = 'https://example.com/oauth2/token'; |
26 | 26 | protected $userRevokeURL = 'https://account.example.com/apps/'; |
27 | - protected $endpointMap = TestEndpoints::class; |
|
27 | + protected $endpointMap = TestEndpoints::class; |
|
28 | 28 | protected $authHeaders = ['foo' => 'bar']; |
29 | 29 | protected $apiHeaders = ['foo' => 'bar']; |
30 | 30 |
@@ -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 | } |
@@ -123,11 +123,9 @@ |
||
123 | 123 | |
124 | 124 | if($expires === 0 || $expires === self::EOL_NEVER_EXPIRES){ |
125 | 125 | $this->expires = self::EOL_NEVER_EXPIRES; |
126 | - } |
|
127 | - elseif($expires > $now){ |
|
126 | + } elseif($expires > $now){ |
|
128 | 127 | $this->expires = $expires; |
129 | - } |
|
130 | - elseif($expires > 0 && $expires < self::EXPIRY_MAX){ |
|
128 | + } elseif($expires > 0 && $expires < self::EXPIRY_MAX){ |
|
131 | 129 | $this->expires = $now + $expires; |
132 | 130 | } |
133 | 131 |
@@ -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. |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @param iterable|null $properties |
85 | 85 | */ |
86 | - public function __construct(iterable $properties = null){ |
|
86 | + public function __construct(iterable $properties = null) { |
|
87 | 87 | parent::__construct($properties); |
88 | 88 | |
89 | 89 | $this->setExpiry($this->expires); |
@@ -108,19 +108,19 @@ discard block |
||
108 | 108 | public function setExpiry(int $expires = null):AccessToken{ |
109 | 109 | $now = \time(); |
110 | 110 | |
111 | - if($expires!== null){ |
|
111 | + if ($expires !== null) { |
|
112 | 112 | $expires = \intval($expires); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $this->expires = self::EOL_UNKNOWN; |
116 | 116 | |
117 | - if($expires === 0 || $expires === self::EOL_NEVER_EXPIRES){ |
|
117 | + if ($expires === 0 || $expires === self::EOL_NEVER_EXPIRES) { |
|
118 | 118 | $this->expires = self::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 < self::EXPIRY_MAX){ |
|
123 | + elseif ($expires > 0 && $expires < self::EXPIRY_MAX) { |
|
124 | 124 | $this->expires = $now + $expires; |
125 | 125 | } |
126 | 126 |
@@ -30,7 +30,7 @@ |
||
30 | 30 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
31 | 31 | * @param \Psr\Log\LoggerInterface|null $logger |
32 | 32 | */ |
33 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
33 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
34 | 34 | $this->options = $options ?? new OAuthOptions; |
35 | 35 | |
36 | 36 | $this->setLogger($logger ?? new NullLogger); |
@@ -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 |
@@ -306,8 +306,7 @@ |
||
306 | 306 | // @todo: content type support |
307 | 307 | if($contentType === 'application/x-www-form-urlencoded'){ |
308 | 308 | $body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)); |
309 | - } |
|
310 | - elseif($contentType === 'application/json'){ |
|
309 | + } elseif($contentType === 'application/json'){ |
|
311 | 310 | $body = $this->streamFactory->createStream(\json_encode($body)); |
312 | 311 | } |
313 | 312 |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * |
141 | 141 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
142 | 142 | */ |
143 | - public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){ |
|
143 | + public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) { |
|
144 | 144 | $this->http = $http; |
145 | 145 | $this->storage = $storage; |
146 | 146 | $this->options = $options; |
@@ -152,10 +152,10 @@ discard block |
||
152 | 152 | |
153 | 153 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
154 | 154 | |
155 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)){ |
|
155 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)) { |
|
156 | 156 | $this->endpoints = new $this->endpointMap; |
157 | 157 | |
158 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
158 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
159 | 159 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
160 | 160 | } |
161 | 161 | |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | * |
169 | 169 | * @return mixed|null |
170 | 170 | */ |
171 | - public function __get(string $name){ |
|
171 | + public function __get(string $name) { |
|
172 | 172 | |
173 | - if(\in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
173 | + if (\in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
174 | 174 | return $this->{$name}; |
175 | 175 | } |
176 | 176 | |
@@ -227,11 +227,11 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function __call(string $name, array $arguments):ResponseInterface{ |
229 | 229 | |
230 | - if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){ |
|
230 | + if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) { |
|
231 | 231 | throw new ApiClientException('MagicAPI not available'); |
232 | 232 | } |
233 | 233 | |
234 | - if(!$this->endpoints->__isset($name)){ |
|
234 | + if (!$this->endpoints->__isset($name)) { |
|
235 | 235 | throw new ApiClientException('endpoint not found: "'.$name.'"'); |
236 | 236 | } |
237 | 237 | |
@@ -244,21 +244,21 @@ discard block |
||
244 | 244 | $path_elements = $m['path_elements'] ?? []; |
245 | 245 | $params_in_url = \count($path_elements); |
246 | 246 | $params = $arguments[$params_in_url] ?? []; |
247 | - $urlparams = \array_slice($arguments,0 , $params_in_url); |
|
247 | + $urlparams = \array_slice($arguments, 0, $params_in_url); |
|
248 | 248 | |
249 | - if($params_in_url > 0){ |
|
249 | + if ($params_in_url > 0) { |
|
250 | 250 | |
251 | - if(\count($urlparams) < $params_in_url){ |
|
251 | + if (\count($urlparams) < $params_in_url) { |
|
252 | 252 | throw new APIClientException('too few URL params, required: '.\implode(', ', $path_elements)); |
253 | 253 | } |
254 | 254 | |
255 | 255 | $endpoint = \sprintf($endpoint, ...$urlparams); |
256 | 256 | } |
257 | 257 | |
258 | - if(\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
258 | + if (\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
259 | 259 | $body = $arguments[$params_in_url + 1] ?? $params; |
260 | 260 | |
261 | - if($params === $body){ |
|
261 | + if ($params === $body) { |
|
262 | 262 | $params = []; |
263 | 263 | } |
264 | 264 | |
@@ -308,24 +308,24 @@ discard block |
||
308 | 308 | $request = $this->requestFactory |
309 | 309 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? [])); |
310 | 310 | |
311 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
311 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
312 | 312 | $request = $request->withAddedHeader($header, $value); |
313 | 313 | } |
314 | 314 | |
315 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
315 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
316 | 316 | $contentType = \strtolower($request->getHeaderLine('content-type')); |
317 | 317 | |
318 | 318 | // @todo: content type support |
319 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
319 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
320 | 320 | $body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)); |
321 | 321 | } |
322 | - elseif($contentType === 'application/json'){ |
|
322 | + elseif ($contentType === 'application/json') { |
|
323 | 323 | $body = $this->streamFactory->createStream(\json_encode($body)); |
324 | 324 | } |
325 | 325 | |
326 | 326 | } |
327 | 327 | |
328 | - if($body instanceof StreamInterface){ |
|
328 | + if ($body instanceof StreamInterface) { |
|
329 | 329 | $request = $request |
330 | 330 | ->withBody($body) |
331 | 331 | ->withHeader('Content-length', $body->getSize()) |
@@ -343,11 +343,11 @@ discard block |
||
343 | 343 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
344 | 344 | |
345 | 345 | // get authorization only if we request the provider API |
346 | - if(\strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
346 | + if (\strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
347 | 347 | $token = $this->storage->getAccessToken($this->serviceName); |
348 | 348 | |
349 | 349 | // attempt to refresh an expired token |
350 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
350 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
351 | 351 | $token = $this->refreshAccessToken($token); |
352 | 352 | } |
353 | 353 |