@@ -335,12 +335,10 @@ |
||
335 | 335 | if(is_array($body)){ |
336 | 336 | if($contentType === 'application/x-www-form-urlencoded'){ |
337 | 337 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
338 | - } |
|
339 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
338 | + } elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
340 | 339 | $body = $this->streamFactory->createStream(json_encode($body)); |
341 | 340 | } |
342 | - } |
|
343 | - elseif(is_string($body)){ |
|
341 | + } elseif(is_string($body)){ |
|
344 | 342 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
345 | 343 | $body = $this->streamFactory->createStream($body); |
346 | 344 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @property string $serviceName |
43 | 43 | * @property string|null $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 = [ |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | OAuthStorageInterface $storage, |
157 | 157 | SettingsContainerInterface $options, |
158 | 158 | LoggerInterface $logger = null |
159 | - ){ |
|
159 | + ) { |
|
160 | 160 | $this->http = $http; |
161 | 161 | $this->storage = $storage; |
162 | 162 | $this->options = $options; |
@@ -168,10 +168,10 @@ discard block |
||
168 | 168 | |
169 | 169 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
170 | 170 | |
171 | - if(!empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
171 | + if (!empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
172 | 172 | $this->endpoints = new $this->endpointMap; |
173 | 173 | |
174 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
174 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
175 | 175 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
176 | 176 | } |
177 | 177 | |
@@ -186,9 +186,9 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @return mixed|null |
188 | 188 | */ |
189 | - public function __get(string $name){ |
|
189 | + public function __get(string $name) { |
|
190 | 190 | |
191 | - if(in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
191 | + if (in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
192 | 192 | return $this->{$name}; |
193 | 193 | } |
194 | 194 | |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function __call(string $endpointName, array $arguments):ResponseInterface{ |
248 | 248 | |
249 | - if(!$this->endpoints instanceof EndpointMap){ |
|
249 | + if (!$this->endpoints instanceof EndpointMap) { |
|
250 | 250 | throw new ApiClientException('MagicAPI not available'); // @codeCoverageIgnore |
251 | 251 | } |
252 | 252 | |
253 | - if(!isset($this->endpoints->{$endpointName})){ |
|
253 | + if (!isset($this->endpoints->{$endpointName})) { |
|
254 | 254 | throw new ApiClientException('endpoint not found: "'.$endpointName.'"'); |
255 | 255 | } |
256 | 256 | |
@@ -270,25 +270,25 @@ discard block |
||
270 | 270 | $path_element_count = count($path_elements); |
271 | 271 | $query_param_count = count($query_params); |
272 | 272 | |
273 | - if($path_element_count > 0){ |
|
273 | + if ($path_element_count > 0) { |
|
274 | 274 | $path = $this->parsePathElements($path, $path_elements, $path_element_count, $arguments); |
275 | 275 | } |
276 | 276 | |
277 | - if($query_param_count > 0){ |
|
277 | + if ($query_param_count > 0) { |
|
278 | 278 | // $params is the first argument after path segments |
279 | 279 | $params = $arguments[$path_element_count] ?? null; |
280 | 280 | |
281 | - if(is_array($params)){ |
|
281 | + if (is_array($params)) { |
|
282 | 282 | $params = $this->cleanQueryParams($this->removeUnlistedParams($params, $query_params)); |
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body){ |
|
286 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body) { |
|
287 | 287 | // if no query params are present, $body is the first argument after any path segments |
288 | 288 | $argPos = $query_param_count > 0 ? 1 : 0; |
289 | 289 | $body = $arguments[$path_element_count + $argPos] ?? null; |
290 | 290 | |
291 | - if(is_array($body)){ |
|
291 | + if (is_array($body)) { |
|
292 | 292 | $body = $this->cleanBodyParams($body); |
293 | 293 | } |
294 | 294 | } |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | // we don't know if all of the given arguments are path elements... |
310 | 310 | $urlparams = array_slice($arguments, 0, $path_element_count); |
311 | 311 | |
312 | - if(count($urlparams) !== $path_element_count){ |
|
312 | + if (count($urlparams) !== $path_element_count) { |
|
313 | 313 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
314 | 314 | } |
315 | 315 | |
316 | - foreach($urlparams as $i => $param){ |
|
316 | + foreach ($urlparams as $i => $param) { |
|
317 | 317 | // ...but we do know that the arguments after the path elements are usually array or null |
318 | - if(!is_scalar($param)){ |
|
318 | + if (!is_scalar($param)) { |
|
319 | 319 | $msg = 'invalid path element value for "%s": %s'; |
320 | 320 | |
321 | 321 | throw new APIClientException(sprintf($msg, $path_elements[$i], var_export($param, true))); |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | protected function removeUnlistedParams(array $params, array $allowed):array{ |
332 | 332 | $query = []; |
333 | 333 | // remove any params that are not listed |
334 | - foreach($params as $key => $value){ |
|
334 | + foreach ($params as $key => $value) { |
|
335 | 335 | |
336 | - if(!in_array($key, $allowed, true)){ |
|
336 | + if (!in_array($key, $allowed, true)) { |
|
337 | 337 | continue; |
338 | 338 | } |
339 | 339 | |
@@ -371,28 +371,28 @@ discard block |
||
371 | 371 | $request = $this->requestFactory |
372 | 372 | ->createRequest($method ?? 'GET', Query::merge($this->getRequestTarget($path), $params ?? [])); |
373 | 373 | |
374 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
374 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
375 | 375 | $request = $request->withAddedHeader($header, $value); |
376 | 376 | } |
377 | 377 | |
378 | - if($request->hasHeader('content-type')){ |
|
378 | + if ($request->hasHeader('content-type')) { |
|
379 | 379 | $contentType = strtolower($request->getHeaderLine('content-type')); |
380 | 380 | |
381 | - if(is_array($body)){ |
|
382 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
381 | + if (is_array($body)) { |
|
382 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
383 | 383 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
384 | 384 | } |
385 | - elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){ |
|
385 | + elseif ($contentType === 'application/json' || $contentType === 'application/vnd.api+json') { |
|
386 | 386 | $body = $this->streamFactory->createStream(json_encode($body)); |
387 | 387 | } |
388 | 388 | } |
389 | - elseif(is_string($body)){ |
|
389 | + elseif (is_string($body)) { |
|
390 | 390 | // we don't check if the given string matches the content type - this is the implementor's responsibility |
391 | 391 | $body = $this->streamFactory->createStream($body); |
392 | 392 | } |
393 | 393 | } |
394 | 394 | |
395 | - if($body instanceof StreamInterface){ |
|
395 | + if ($body instanceof StreamInterface) { |
|
396 | 396 | $request = $request |
397 | 397 | ->withBody($body) |
398 | 398 | ->withHeader('Content-length', (string)$body->getSize()) |
@@ -414,15 +414,15 @@ discard block |
||
414 | 414 | protected function getRequestTarget(string $uri):string{ |
415 | 415 | $parsedURL = parse_url($uri); |
416 | 416 | |
417 | - if(!isset($parsedURL['path'])){ |
|
417 | + if (!isset($parsedURL['path'])) { |
|
418 | 418 | throw new ProviderException('invalid path'); |
419 | 419 | } |
420 | 420 | |
421 | 421 | // for some reason we were given a host name |
422 | - if(isset($parsedURL['host'])){ |
|
422 | + if (isset($parsedURL['host'])) { |
|
423 | 423 | |
424 | 424 | // back out if it doesn't match |
425 | - if($parsedURL['host'] !== parse_url($this->apiURL, PHP_URL_HOST)){ |
|
425 | + if ($parsedURL['host'] !== parse_url($this->apiURL, PHP_URL_HOST)) { |
|
426 | 426 | throw new ProviderException('given host does not match provider host'); |
427 | 427 | } |
428 | 428 | |
@@ -440,15 +440,15 @@ discard block |
||
440 | 440 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
441 | 441 | |
442 | 442 | // get authorization only if we request the provider API |
443 | - if(strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
443 | + if (strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
444 | 444 | $token = $this->storage->getAccessToken($this->serviceName); |
445 | 445 | |
446 | 446 | // attempt to refresh an expired token |
447 | - if( |
|
447 | + if ( |
|
448 | 448 | $this instanceof TokenRefresh |
449 | 449 | && $this->options->tokenAutoRefresh |
450 | 450 | && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN) |
451 | - ){ |
|
451 | + ) { |
|
452 | 452 | $token = $this->refreshAccessToken($token); |
453 | 453 | } |
454 | 454 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | /** |
14 | 14 | * The settings for the OAuth provider |
15 | 15 | */ |
16 | -trait OAuthOptionsTrait{ |
|
16 | +trait OAuthOptionsTrait { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * The application key (or id) given by your provider |
@@ -16,7 +16,7 @@ |
||
16 | 16 | /** |
17 | 17 | * Specifies the methods required for an OAuth storage adapter |
18 | 18 | */ |
19 | -interface OAuthStorageInterface extends LoggerAwareInterface{ |
|
19 | +interface OAuthStorageInterface extends LoggerAwareInterface { |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Stores an AccessToken for the given $service |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Implements a memory storage adapter. Memory storage is not persistent as tokens are only stored during script runtime. |
19 | 19 | */ |
20 | -class MemoryStorage extends OAuthStorageAbstract{ |
|
20 | +class MemoryStorage extends OAuthStorageAbstract { |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * the token storage array |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function getAccessToken(string $service):AccessToken{ |
45 | 45 | |
46 | - if($this->hasAccessToken($service)){ |
|
46 | + if ($this->hasAccessToken($service)) { |
|
47 | 47 | return $this->tokens[$service]; |
48 | 48 | } |
49 | 49 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function clearAccessToken(string $service):bool{ |
64 | 64 | |
65 | - if(array_key_exists($service, $this->tokens)){ |
|
65 | + if (array_key_exists($service, $this->tokens)) { |
|
66 | 66 | unset($this->tokens[$service]); |
67 | 67 | } |
68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | public function clearAllAccessTokens():bool{ |
76 | 76 | |
77 | - foreach(array_keys($this->tokens) as $service){ |
|
77 | + foreach (array_keys($this->tokens) as $service) { |
|
78 | 78 | unset($this->tokens[$service]); |
79 | 79 | } |
80 | 80 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function getCSRFState(string $service):string{ |
99 | 99 | |
100 | - if($this->hasCSRFState($service)){ |
|
100 | + if ($this->hasCSRFState($service)) { |
|
101 | 101 | return $this->states[$service]; |
102 | 102 | } |
103 | 103 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function clearCSRFState(string $service):bool{ |
118 | 118 | |
119 | - if(array_key_exists($service, $this->states)){ |
|
119 | + if (array_key_exists($service, $this->states)) { |
|
120 | 120 | unset($this->states[$service]); |
121 | 121 | } |
122 | 122 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | /** |
20 | 20 | * Implements ab anstract 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 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
34 | 34 | * @param \Psr\Log\LoggerInterface|null $logger |
35 | 35 | */ |
36 | - public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null){ |
|
36 | + public function __construct(SettingsContainerInterface $options = null, LoggerInterface $logger = null) { |
|
37 | 37 | $this->options = $options ?? new OAuthOptions; |
38 | 38 | |
39 | 39 | $this->setLogger($logger ?? new NullLogger); |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function fromStorage($data):AccessToken{ |
55 | 55 | |
56 | - if(!is_string($data)){ |
|
56 | + if (!is_string($data)) { |
|
57 | 57 | throw new OAuthStorageException('invalid data'); |
58 | 58 | } |
59 | 59 |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | /** |
21 | 21 | * Implements a session storage adapter. Session storage is half persistent as tokens are stored for the duration of the session. |
22 | 22 | */ |
23 | -class SessionStorage extends OAuthStorageAbstract{ |
|
23 | +class SessionStorage extends OAuthStorageAbstract { |
|
24 | 24 | |
25 | 25 | /** |
26 | 26 | * the key name for the token storage array in $_SESSION |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
39 | 39 | */ |
40 | - public function __construct(SettingsContainerInterface $options = null){ |
|
40 | + public function __construct(SettingsContainerInterface $options = null) { |
|
41 | 41 | parent::__construct($options); |
42 | 42 | |
43 | 43 | $this->tokenVar = $this->options->sessionTokenVar; |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | |
46 | 46 | // Determine if the session has started. |
47 | 47 | // @link http://stackoverflow.com/a/18542272/1470961 |
48 | - if($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)){ |
|
48 | + if ($this->options->sessionStart && !(session_status() !== PHP_SESSION_NONE)) { |
|
49 | 49 | session_start(); |
50 | 50 | } |
51 | 51 | |
52 | - if(!isset($_SESSION[$this->tokenVar])){ |
|
52 | + if (!isset($_SESSION[$this->tokenVar])) { |
|
53 | 53 | $_SESSION[$this->tokenVar] = []; |
54 | 54 | } |
55 | 55 | |
56 | - if(!isset($_SESSION[$this->stateVar])){ |
|
56 | + if (!isset($_SESSION[$this->stateVar])) { |
|
57 | 57 | $_SESSION[$this->stateVar] = []; |
58 | 58 | } |
59 | 59 | |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @codeCoverageIgnore |
66 | 66 | */ |
67 | - public function __destruct(){ |
|
68 | - if($this->options->sessionStart){ |
|
67 | + public function __destruct() { |
|
68 | + if ($this->options->sessionStart) { |
|
69 | 69 | session_write_close(); |
70 | 70 | } |
71 | 71 | } |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function getAccessToken(string $service):AccessToken{ |
86 | 86 | |
87 | - if($this->hasAccessToken($service)){ |
|
87 | + if ($this->hasAccessToken($service)) { |
|
88 | 88 | return $this->fromStorage($_SESSION[$this->tokenVar][$service]); |
89 | 89 | } |
90 | 90 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function clearAccessToken(string $service):bool{ |
105 | 105 | |
106 | - if(array_key_exists($service, $_SESSION[$this->tokenVar])){ |
|
106 | + if (array_key_exists($service, $_SESSION[$this->tokenVar])) { |
|
107 | 107 | unset($_SESSION[$this->tokenVar][$service]); |
108 | 108 | } |
109 | 109 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function clearAllAccessTokens():bool{ |
117 | 117 | |
118 | - foreach(array_keys($_SESSION[$this->tokenVar]) as $service){ |
|
118 | + foreach (array_keys($_SESSION[$this->tokenVar]) as $service) { |
|
119 | 119 | unset($_SESSION[$this->tokenVar][$service]); |
120 | 120 | } |
121 | 121 | |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | */ |
139 | 139 | public function getCSRFState(string $service):string{ |
140 | 140 | |
141 | - if($this->hasCSRFState($service)){ |
|
141 | + if ($this->hasCSRFState($service)) { |
|
142 | 142 | return $_SESSION[$this->stateVar][$service]; |
143 | 143 | } |
144 | 144 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | */ |
158 | 158 | public function clearCSRFState(string $service):bool{ |
159 | 159 | |
160 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
160 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
161 | 161 | unset($_SESSION[$this->stateVar][$service]); |
162 | 162 | } |
163 | 163 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | * |
16 | 16 | * @link https://tools.ietf.org/html/rfc6749#section-10.4 |
17 | 17 | */ |
18 | -interface TokenRefresh{ |
|
18 | +interface TokenRefresh { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Tries to refresh an existing AccessToken with an associated refresh token and returns a fresh AccessToken. |
@@ -15,7 +15,7 @@ |
||
15 | 15 | * |
16 | 16 | * @link https://tools.ietf.org/html/rfc6749#section-4.4 |
17 | 17 | */ |
18 | -interface ClientCredentials{ |
|
18 | +interface ClientCredentials { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Obtains an OAuth2 client credentials token and returns an AccessToken |
@@ -13,7 +13,7 @@ |
||
13 | 13 | /** |
14 | 14 | * Specifies the basic methods for an OAuth1 provider. |
15 | 15 | */ |
16 | -interface OAuth1Interface extends OAuthInterface{ |
|
16 | +interface OAuth1Interface extends OAuthInterface { |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Obtains an OAuth1 request token and returns an AccessToken object for use in the authentication request. |