@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | |
17 | -class MemoryStorage extends OAuthStorageAbstract{ |
|
17 | +class MemoryStorage extends OAuthStorageAbstract { |
|
18 | 18 | |
19 | 19 | /** |
20 | 20 | * @var array |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function getAccessToken(string $service):AccessToken{ |
48 | 48 | |
49 | - if($this->hasAccessToken($service)){ |
|
49 | + if ($this->hasAccessToken($service)) { |
|
50 | 50 | return $this->tokens[$service]; |
51 | 51 | } |
52 | 52 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | */ |
70 | 70 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
71 | 71 | |
72 | - if(array_key_exists($service, $this->tokens)){ |
|
72 | + if (array_key_exists($service, $this->tokens)) { |
|
73 | 73 | unset($this->tokens[$service]); |
74 | 74 | } |
75 | 75 | |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function clearAllAccessTokens():OAuthStorageInterface{ |
83 | 83 | |
84 | - foreach(array_keys($this->tokens) as $service){ |
|
84 | + foreach (array_keys($this->tokens) as $service) { |
|
85 | 85 | unset($this->tokens[$service]); // trigger the memzero destructor |
86 | 86 | } |
87 | 87 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | public function getCSRFState(string $service):string{ |
112 | 112 | |
113 | - if($this->hasCSRFState($service)){ |
|
113 | + if ($this->hasCSRFState($service)) { |
|
114 | 114 | return $this->states[$service]; |
115 | 115 | } |
116 | 116 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | */ |
134 | 134 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
135 | 135 | |
136 | - if(array_key_exists($service, $this->states)){ |
|
136 | + if (array_key_exists($service, $this->states)) { |
|
137 | 137 | unset($this->states[$service]); |
138 | 138 | } |
139 | 139 |
@@ -83,8 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
85 | 85 | $_SESSION[$this->sessionVar][$service] = $token; |
86 | - } |
|
87 | - else{ |
|
86 | + } else{ |
|
88 | 87 | $_SESSION[$this->sessionVar] = [$service => $token]; |
89 | 88 | } |
90 | 89 | |
@@ -153,8 +152,7 @@ discard block |
||
153 | 152 | |
154 | 153 | if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
155 | 154 | $_SESSION[$this->stateVar][$service] = $state; |
156 | - } |
|
157 | - else{ |
|
155 | + } else{ |
|
158 | 156 | $_SESSION[$this->stateVar] = [$service => $state]; |
159 | 157 | } |
160 | 158 |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\OAuth\Core\AccessToken; |
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | |
18 | -class SessionStorage extends OAuthStorageAbstract{ |
|
18 | +class SessionStorage extends OAuthStorageAbstract { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var bool |
@@ -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->sessionVar = $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->sessionVar])){ |
|
52 | + if (!isset($_SESSION[$this->sessionVar])) { |
|
53 | 53 | $_SESSION[$this->sessionVar] = []; |
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 | } |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
80 | 80 | $token = $token->toJSON(); |
81 | 81 | |
82 | - if(isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])){ |
|
82 | + if (isset($_SESSION[$this->sessionVar]) && is_array($_SESSION[$this->sessionVar])) { |
|
83 | 83 | $_SESSION[$this->sessionVar][$service] = $token; |
84 | 84 | } |
85 | - else{ |
|
85 | + else { |
|
86 | 86 | $_SESSION[$this->sessionVar] = [$service => $token]; |
87 | 87 | } |
88 | 88 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function getAccessToken(string $service):AccessToken{ |
99 | 99 | |
100 | - if($this->hasAccessToken($service)){ |
|
100 | + if ($this->hasAccessToken($service)) { |
|
101 | 101 | return (new AccessToken)->fromJSON($_SESSION[$this->sessionVar][$service]); |
102 | 102 | } |
103 | 103 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
122 | 122 | |
123 | - if(array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
123 | + if (array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
124 | 124 | unset($_SESSION[$this->sessionVar][$service]); |
125 | 125 | } |
126 | 126 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public function clearAllAccessTokens():OAuthStorageInterface{ |
134 | 134 | |
135 | - foreach(array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
135 | + foreach (array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
136 | 136 | unset($_SESSION[$this->sessionVar][$service]); // trigger the memzero destructor |
137 | 137 | } |
138 | 138 | |
@@ -149,10 +149,10 @@ discard block |
||
149 | 149 | */ |
150 | 150 | public function storeCSRFState(string $service, string $state):OAuthStorageInterface{ |
151 | 151 | |
152 | - if(isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])){ |
|
152 | + if (isset($_SESSION[$this->stateVar]) && is_array($_SESSION[$this->stateVar])) { |
|
153 | 153 | $_SESSION[$this->stateVar][$service] = $state; |
154 | 154 | } |
155 | - else{ |
|
155 | + else { |
|
156 | 156 | $_SESSION[$this->stateVar] = [$service => $state]; |
157 | 157 | } |
158 | 158 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function getCSRFState(string $service):string{ |
169 | 169 | |
170 | - if($this->hasCSRFState($service)){ |
|
170 | + if ($this->hasCSRFState($service)) { |
|
171 | 171 | return $_SESSION[$this->stateVar][$service]; |
172 | 172 | } |
173 | 173 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | */ |
191 | 191 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
192 | 192 | |
193 | - if(array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
193 | + if (array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
194 | 194 | unset($_SESSION[$this->stateVar][$service]); |
195 | 195 | } |
196 | 196 |
@@ -35,7 +35,7 @@ |
||
35 | 35 | ]; |
36 | 36 | |
37 | 37 | /** @var \chillerlan\Settings\SettingsContainerInterface $options */ |
38 | -$options = new class($options_arr) extends OAuthOptions{ |
|
38 | +$options = new class($options_arr) extends OAuthOptions { |
|
39 | 39 | use LogOptionsTrait; |
40 | 40 | |
41 | 41 | protected $sleep; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @property \Psr\Http\Message\RequestFactoryInterface $requestFactory |
25 | 25 | * @property \Psr\Http\Message\StreamFactoryInterface $streamFactory |
26 | 26 | */ |
27 | -trait OAuth2TokenRefreshTrait{ |
|
27 | +trait OAuth2TokenRefreshTrait { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @param \chillerlan\OAuth\Core\AccessToken $token |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function refreshAccessToken(AccessToken $token = null):AccessToken{ |
36 | 36 | |
37 | - if($token === null){ |
|
37 | + if ($token === null) { |
|
38 | 38 | $token = $this->storage->getAccessToken($this->serviceName); |
39 | 39 | } |
40 | 40 | |
41 | 41 | $refreshToken = $token->refreshToken; |
42 | 42 | |
43 | - if(empty($refreshToken)){ |
|
43 | + if (empty($refreshToken)) { |
|
44 | 44 | |
45 | - if(!$this instanceof AccessTokenForRefresh){ |
|
45 | + if (!$this instanceof AccessTokenForRefresh) { |
|
46 | 46 | throw new ProviderException(sprintf('no refresh token available, token expired [%s]', date('Y-m-d h:i:s A', $token->expires))); |
47 | 47 | } |
48 | 48 | |
@@ -63,13 +63,13 @@ discard block |
||
63 | 63 | ->withBody($this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738))) |
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 | |
70 | 70 | $newToken = $this->parseTokenResponse($this->http->sendRequest($request)); |
71 | 71 | |
72 | - if(empty($newToken->refreshToken)){ |
|
72 | + if (empty($newToken->refreshToken)) { |
|
73 | 73 | $newToken->refreshToken = $refreshToken; |
74 | 74 | } |
75 | 75 |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @property \Psr\Http\Message\RequestFactoryInterface $requestFactory |
25 | 25 | * @property \Psr\Http\Message\StreamFactoryInterface $streamFactory |
26 | 26 | */ |
27 | -trait OAuth2ClientCredentialsTrait{ |
|
27 | +trait OAuth2ClientCredentialsTrait { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @param array $scopes |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function getClientCredentialsToken(array $scopes = null):AccessToken{ |
35 | 35 | $params = ['grant_type' => 'client_credentials']; |
36 | 36 | |
37 | - if($scopes !== null){ |
|
37 | + if ($scopes !== null) { |
|
38 | 38 | $params['scope'] = implode($this->scopesDelimiter, $scopes); |
39 | 39 | } |
40 | 40 | |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | ->withBody($this->streamFactory->createStream(http_build_query($params, '', '&', PHP_QUERY_RFC1738))) |
46 | 46 | ; |
47 | 47 | |
48 | - foreach($this->authHeaders as $header => $value){ |
|
48 | + foreach ($this->authHeaders as $header => $value) { |
|
49 | 49 | $request = $request->withAddedHeader($header, $value); |
50 | 50 | } |
51 | 51 |
@@ -277,8 +277,7 @@ |
||
277 | 277 | |
278 | 278 | if($contentType === 'application/x-www-form-urlencoded'){ |
279 | 279 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
280 | - } |
|
281 | - elseif($contentType === 'application/json'){ |
|
280 | + } elseif($contentType === 'application/json'){ |
|
282 | 281 | $body = $this->streamFactory->createStream(json_encode($body)); |
283 | 282 | } |
284 | 283 |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
124 | 124 | */ |
125 | - public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){ |
|
125 | + public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) { |
|
126 | 126 | $this->http = $http; |
127 | 127 | $this->storage = $storage; |
128 | 128 | $this->options = $options; |
@@ -134,10 +134,10 @@ discard block |
||
134 | 134 | |
135 | 135 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
136 | 136 | |
137 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)){ |
|
137 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && class_exists($this->endpointMap)) { |
|
138 | 138 | $this->endpoints = new $this->endpointMap; |
139 | 139 | |
140 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
140 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
141 | 141 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
142 | 142 | } |
143 | 143 | |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @return string|null |
152 | 152 | */ |
153 | - public function __get(string $name):?string{ |
|
153 | + public function __get(string $name): ?string{ |
|
154 | 154 | |
155 | - if(!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)){ |
|
155 | + if (!in_array($name, ['serviceName', 'authURL', 'accessTokenURL', 'revokeURL', 'userRevokeURL', 'apiURL'], true)) { |
|
156 | 156 | return null; |
157 | 157 | } |
158 | 158 | |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | */ |
210 | 210 | public function __call(string $name, array $arguments):ResponseInterface{ |
211 | 211 | |
212 | - if(!$this instanceof ApiClientInterface){ |
|
212 | + if (!$this instanceof ApiClientInterface) { |
|
213 | 213 | throw new ApiClientException('MagicAPI not available'); |
214 | 214 | } |
215 | 215 | |
216 | - if(!$this->endpoints->__isset($name)){ |
|
216 | + if (!$this->endpoints->__isset($name)) { |
|
217 | 217 | throw new ApiClientException('endpoint not found'); |
218 | 218 | } |
219 | 219 | |
@@ -226,21 +226,21 @@ discard block |
||
226 | 226 | $path_elements = $m['path_elements'] ?? []; |
227 | 227 | $params_in_url = count($path_elements); |
228 | 228 | $params = $arguments[$params_in_url] ?? []; |
229 | - $urlparams = array_slice($arguments,0 , $params_in_url); |
|
229 | + $urlparams = array_slice($arguments, 0, $params_in_url); |
|
230 | 230 | |
231 | - if($params_in_url > 0){ |
|
231 | + if ($params_in_url > 0) { |
|
232 | 232 | |
233 | - if(count($urlparams) < $params_in_url){ |
|
233 | + if (count($urlparams) < $params_in_url) { |
|
234 | 234 | throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements)); |
235 | 235 | } |
236 | 236 | |
237 | 237 | $endpoint = sprintf($endpoint, ...$urlparams); |
238 | 238 | } |
239 | 239 | |
240 | - if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
240 | + if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
241 | 241 | $body = $arguments[$params_in_url + 1] ?? $params; |
242 | 242 | |
243 | - if($params === $body){ |
|
243 | + if ($params === $body) { |
|
244 | 244 | $params = []; |
245 | 245 | } |
246 | 246 | |
@@ -290,23 +290,23 @@ discard block |
||
290 | 290 | $request = $this->requestFactory |
291 | 291 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? [])); |
292 | 292 | |
293 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
293 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
294 | 294 | $contentType = strtolower($request->getHeaderLine('content-type')); |
295 | 295 | |
296 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
296 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
297 | 297 | $body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738)); |
298 | 298 | } |
299 | - elseif($contentType === 'application/json'){ |
|
299 | + elseif ($contentType === 'application/json') { |
|
300 | 300 | $body = $this->streamFactory->createStream(json_encode($body)); |
301 | 301 | } |
302 | 302 | |
303 | 303 | } |
304 | 304 | |
305 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
305 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
306 | 306 | $request = $request->withAddedHeader($header, $value); |
307 | 307 | } |
308 | 308 | |
309 | - if($body instanceof StreamInterface){ |
|
309 | + if ($body instanceof StreamInterface) { |
|
310 | 310 | $request = $request->withBody($body); |
311 | 311 | } |
312 | 312 | |
@@ -321,11 +321,11 @@ discard block |
||
321 | 321 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
322 | 322 | |
323 | 323 | // get authorization only if we request the provider API |
324 | - if($request->getUri()->getHost() === parse_url($this->apiURL, PHP_URL_HOST)){ |
|
324 | + if ($request->getUri()->getHost() === parse_url($this->apiURL, PHP_URL_HOST)) { |
|
325 | 325 | $token = $this->storage->getAccessToken($this->serviceName); |
326 | 326 | |
327 | 327 | // attempt to refresh an expired token |
328 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
328 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
329 | 329 | $token = $this->refreshAccessToken($token); |
330 | 330 | } |
331 | 331 |
@@ -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 | * @var string |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use chillerlan\OAuth\{Core\AccessToken, OAuthOptions}; |
16 | 16 | use chillerlan\Settings\SettingsContainerInterface; |
17 | 17 | |
18 | -abstract class OAuthStorageAbstract implements OAuthStorageInterface{ |
|
18 | +abstract class OAuthStorageAbstract implements OAuthStorageInterface { |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * @var \chillerlan\OAuth\OAuthOptions |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
29 | 29 | */ |
30 | - public function __construct(SettingsContainerInterface $options = null){ |
|
30 | + public function __construct(SettingsContainerInterface $options = null) { |
|
31 | 31 | $this->options = $options ?? new OAuthOptions; |
32 | 32 | } |
33 | 33 |
@@ -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'; |