@@ -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 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | ->withBody($this->streamFactory->createStream(\http_build_query($params, '', '&', \PHP_QUERY_RFC1738))) |
47 | 47 | ; |
48 | 48 | |
49 | - foreach($this->authHeaders as $header => $value){ |
|
49 | + foreach ($this->authHeaders as $header => $value) { |
|
50 | 50 | $request = $request->withAddedHeader($header, $value); |
51 | 51 | } |
52 | 52 |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @throws \chillerlan\HTTP\MagicAPI\ApiClientException |
130 | 130 | */ |
131 | - public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null){ |
|
131 | + public function __construct(ClientInterface $http, OAuthStorageInterface $storage, SettingsContainerInterface $options, LoggerInterface $logger = null) { |
|
132 | 132 | $this->http = $http; |
133 | 133 | $this->storage = $storage; |
134 | 134 | $this->options = $options; |
@@ -140,10 +140,10 @@ discard block |
||
140 | 140 | |
141 | 141 | $this->serviceName = (new ReflectionClass($this))->getShortName(); |
142 | 142 | |
143 | - if($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)){ |
|
143 | + if ($this instanceof ApiClientInterface && !empty($this->endpointMap) && \class_exists($this->endpointMap)) { |
|
144 | 144 | $this->endpoints = new $this->endpointMap; |
145 | 145 | |
146 | - if(!$this->endpoints instanceof EndpointMapInterface){ |
|
146 | + if (!$this->endpoints instanceof EndpointMapInterface) { |
|
147 | 147 | throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore |
148 | 148 | } |
149 | 149 | |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return string|null |
158 | 158 | */ |
159 | - public function __get(string $name):?string{ |
|
159 | + public function __get(string $name): ?string{ |
|
160 | 160 | |
161 | - if(\in_array($name, $this::ALLOWED_PROPERTIES, true)){ |
|
161 | + if (\in_array($name, $this::ALLOWED_PROPERTIES, true)) { |
|
162 | 162 | return $this->{$name}; |
163 | 163 | } |
164 | 164 | |
@@ -215,11 +215,11 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function __call(string $name, array $arguments):ResponseInterface{ |
217 | 217 | |
218 | - if(!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap){ |
|
218 | + if (!$this instanceof ApiClientInterface || !$this->endpoints instanceof EndpointMap) { |
|
219 | 219 | throw new ApiClientException('MagicAPI not available'); |
220 | 220 | } |
221 | 221 | |
222 | - if(!$this->endpoints->__isset($name)){ |
|
222 | + if (!$this->endpoints->__isset($name)) { |
|
223 | 223 | throw new ApiClientException('endpoint not found'); |
224 | 224 | } |
225 | 225 | |
@@ -232,21 +232,21 @@ discard block |
||
232 | 232 | $path_elements = $m['path_elements'] ?? []; |
233 | 233 | $params_in_url = \count($path_elements); |
234 | 234 | $params = $arguments[$params_in_url] ?? []; |
235 | - $urlparams = \array_slice($arguments,0 , $params_in_url); |
|
235 | + $urlparams = \array_slice($arguments, 0, $params_in_url); |
|
236 | 236 | |
237 | - if($params_in_url > 0){ |
|
237 | + if ($params_in_url > 0) { |
|
238 | 238 | |
239 | - if(\count($urlparams) < $params_in_url){ |
|
239 | + if (\count($urlparams) < $params_in_url) { |
|
240 | 240 | throw new APIClientException('too few URL params, required: '.\implode(', ', $path_elements)); |
241 | 241 | } |
242 | 242 | |
243 | 243 | $endpoint = \sprintf($endpoint, ...$urlparams); |
244 | 244 | } |
245 | 245 | |
246 | - if(\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])){ |
|
246 | + if (\in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE'])) { |
|
247 | 247 | $body = $arguments[$params_in_url + 1] ?? $params; |
248 | 248 | |
249 | - if($params === $body){ |
|
249 | + if ($params === $body) { |
|
250 | 250 | $params = []; |
251 | 251 | } |
252 | 252 | |
@@ -296,24 +296,24 @@ discard block |
||
296 | 296 | $request = $this->requestFactory |
297 | 297 | ->createRequest($method ?? 'GET', Psr7\merge_query($this->apiURL.$path, $params ?? [])); |
298 | 298 | |
299 | - foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){ |
|
299 | + foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) { |
|
300 | 300 | $request = $request->withAddedHeader($header, $value); |
301 | 301 | } |
302 | 302 | |
303 | - if(is_array($body) && $request->hasHeader('content-type')){ |
|
303 | + if (is_array($body) && $request->hasHeader('content-type')) { |
|
304 | 304 | $contentType = \strtolower($request->getHeaderLine('content-type')); |
305 | 305 | |
306 | 306 | // @todo: content type support |
307 | - if($contentType === 'application/x-www-form-urlencoded'){ |
|
307 | + if ($contentType === 'application/x-www-form-urlencoded') { |
|
308 | 308 | $body = $this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738)); |
309 | 309 | } |
310 | - elseif($contentType === 'application/json'){ |
|
310 | + elseif ($contentType === 'application/json') { |
|
311 | 311 | $body = $this->streamFactory->createStream(\json_encode($body)); |
312 | 312 | } |
313 | 313 | |
314 | 314 | } |
315 | 315 | |
316 | - if($body instanceof StreamInterface){ |
|
316 | + if ($body instanceof StreamInterface) { |
|
317 | 317 | $request = $request |
318 | 318 | ->withBody($body) |
319 | 319 | ->withHeader('Content-length', $body->getSize()) |
@@ -331,11 +331,11 @@ discard block |
||
331 | 331 | public function sendRequest(RequestInterface $request):ResponseInterface{ |
332 | 332 | |
333 | 333 | // get authorization only if we request the provider API |
334 | - if(\strpos((string)$request->getUri(), $this->apiURL) === 0){ |
|
334 | + if (\strpos((string)$request->getUri(), $this->apiURL) === 0) { |
|
335 | 335 | $token = $this->storage->getAccessToken($this->serviceName); |
336 | 336 | |
337 | 337 | // attempt to refresh an expired token |
338 | - if($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)){ |
|
338 | + if ($this instanceof TokenRefresh && $this->options->tokenAutoRefresh && ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)) { |
|
339 | 339 | $token = $this->refreshAccessToken($token); |
340 | 340 | } |
341 | 341 |
@@ -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 |
@@ -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 | |
@@ -64,13 +64,13 @@ discard block |
||
64 | 64 | ->withBody($this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738))) |
65 | 65 | ; |
66 | 66 | |
67 | - foreach($this->authHeaders as $header => $value){ |
|
67 | + foreach ($this->authHeaders as $header => $value) { |
|
68 | 68 | $request = $request->withAddedHeader($header, $value); |
69 | 69 | } |
70 | 70 | |
71 | 71 | $newToken = $this->parseTokenResponse($this->http->sendRequest($request)); |
72 | 72 | |
73 | - if(empty($newToken->refreshToken)){ |
|
73 | + if (empty($newToken->refreshToken)) { |
|
74 | 74 | $newToken->refreshToken = $refreshToken; |
75 | 75 | } |
76 | 76 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @method array setState(array $params) |
23 | 23 | * @method \chillerlan\OAuth\Core\OAuth2Interface checkState(string $state = null) |
24 | 24 | */ |
25 | -abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface{ |
|
25 | +abstract class OAuth2Provider extends OAuthProvider implements OAuth2Interface { |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @var int |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | public function getAuthURL(array $params = null, array $scopes = null):UriInterface{ |
59 | 59 | $params = $params ?? []; |
60 | 60 | |
61 | - if(isset($params['client_secret'])){ |
|
61 | + if (isset($params['client_secret'])) { |
|
62 | 62 | unset($params['client_secret']); |
63 | 63 | } |
64 | 64 | |
@@ -69,11 +69,11 @@ discard block |
||
69 | 69 | 'type' => 'web_server', |
70 | 70 | ]); |
71 | 71 | |
72 | - if($scopes !== null){ |
|
72 | + if ($scopes !== null) { |
|
73 | 73 | $params['scope'] = \implode($this->scopesDelimiter, $scopes); |
74 | 74 | } |
75 | 75 | |
76 | - if($this instanceof CSRFToken){ |
|
76 | + if ($this instanceof CSRFToken) { |
|
77 | 77 | $params = $this->setState($params); |
78 | 78 | } |
79 | 79 | |
@@ -89,19 +89,19 @@ discard block |
||
89 | 89 | protected function parseTokenResponse(ResponseInterface $response):AccessToken{ |
90 | 90 | $data = \json_decode(Psr7\decompress_content($response), true); // silly amazon... |
91 | 91 | |
92 | - if(!\is_array($data)){ |
|
92 | + if (!\is_array($data)) { |
|
93 | 93 | throw new ProviderException('unable to parse token response'); |
94 | 94 | } |
95 | 95 | |
96 | - foreach(['error_description', 'error'] as $field){ |
|
96 | + foreach (['error_description', 'error'] as $field) { |
|
97 | 97 | |
98 | - if(isset($data[$field])){ |
|
98 | + if (isset($data[$field])) { |
|
99 | 99 | throw new ProviderException('error retrieving access token: "'.$data[$field].'"'); |
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
103 | 103 | |
104 | - if(!isset($data['access_token'])){ |
|
104 | + if (!isset($data['access_token'])) { |
|
105 | 105 | throw new ProviderException('token missing'); |
106 | 106 | } |
107 | 107 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function getAccessToken(string $code, string $state = null):AccessToken{ |
129 | 129 | |
130 | - if($this instanceof CSRFToken){ |
|
130 | + if ($this instanceof CSRFToken) { |
|
131 | 131 | $this->checkState($state); |
132 | 132 | } |
133 | 133 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | ->withHeader('Accept-Encoding', 'identity') |
146 | 146 | ->withBody($this->streamFactory->createStream(\http_build_query($body, '', '&', \PHP_QUERY_RFC1738))); |
147 | 147 | |
148 | - foreach($this->authHeaders as $header => $value){ |
|
148 | + foreach ($this->authHeaders as $header => $value) { |
|
149 | 149 | $request = $request->withHeader($header, $value); |
150 | 150 | } |
151 | 151 | |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function getRequestAuthorization(RequestInterface $request, AccessToken $token):RequestInterface{ |
167 | 167 | |
168 | - if(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)){ |
|
168 | + if (\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)) { |
|
169 | 169 | $request = $request->withHeader('Authorization', OAuth2Interface::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken); |
170 | 170 | } |
171 | - elseif(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
171 | + elseif (\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)) { |
|
172 | 172 | $uri = Psr7\merge_query((string)$request->getUri(), [OAuth2Interface::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]); |
173 | 173 | |
174 | 174 | $request = $request->withUri($this->uriFactory->createUri($uri)); |
175 | 175 | } |
176 | - else{ |
|
176 | + else { |
|
177 | 177 | throw new ProviderException('invalid auth type'); |
178 | 178 | } |
179 | 179 |
@@ -167,13 +167,11 @@ |
||
167 | 167 | |
168 | 168 | if(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_HEADER)){ |
169 | 169 | $request = $request->withHeader('Authorization', OAuth2Interface::AUTH_METHODS_HEADER[$this->authMethod].$token->accessToken); |
170 | - } |
|
171 | - elseif(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
170 | + } elseif(\array_key_exists($this->authMethod, OAuth2Interface::AUTH_METHODS_QUERY)){ |
|
172 | 171 | $uri = Psr7\merge_query((string)$request->getUri(), [OAuth2Interface::AUTH_METHODS_QUERY[$this->authMethod] => $token->accessToken]); |
173 | 172 | |
174 | 173 | $request = $request->withUri($this->uriFactory->createUri($uri)); |
175 | - } |
|
176 | - else{ |
|
174 | + } else{ |
|
177 | 175 | throw new ProviderException('invalid auth type'); |
178 | 176 | } |
179 | 177 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | use DateTime; |
19 | 19 | use Psr\Http\Message\{RequestInterface, ResponseInterface, UriInterface}; |
20 | 20 | |
21 | -abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface{ |
|
21 | +abstract class OAuth1Provider extends OAuthProvider implements OAuth1Interface { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @var string |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | ->withHeader('Accept-Encoding', 'identity') |
63 | 63 | ; |
64 | 64 | |
65 | - foreach($this->authHeaders as $header => $value){ |
|
65 | + foreach ($this->authHeaders as $header => $value) { |
|
66 | 66 | $request = $request->withAddedHeader($header, $value); |
67 | 67 | } |
68 | 68 | |
@@ -79,17 +79,17 @@ discard block |
||
79 | 79 | protected function parseTokenResponse(ResponseInterface $response, bool $checkCallbackConfirmed = null):AccessToken{ |
80 | 80 | \parse_str(Psr7\decompress_content($response), $data); |
81 | 81 | |
82 | - if(!$data || !\is_array($data)){ |
|
82 | + if (!$data || !\is_array($data)) { |
|
83 | 83 | throw new ProviderException('unable to parse token response'); |
84 | 84 | } |
85 | - elseif(isset($data['error'])){ |
|
85 | + elseif (isset($data['error'])) { |
|
86 | 86 | throw new ProviderException('error retrieving access token: '.$data['error']); |
87 | 87 | } |
88 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
88 | + elseif (!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])) { |
|
89 | 89 | throw new ProviderException('invalid token'); |
90 | 90 | } |
91 | 91 | |
92 | - if($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')){ |
|
92 | + if ($checkCallbackConfirmed && (!isset($data['oauth_callback_confirmed']) || $data['oauth_callback_confirmed'] !== 'true')) { |
|
93 | 93 | throw new ProviderException('oauth callback unconfirmed'); |
94 | 94 | } |
95 | 95 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | protected function getSignature(string $url, array $params, string $method, string $accessTokenSecret = null):string{ |
136 | 136 | $parseURL = \parse_url($url); |
137 | 137 | |
138 | - if(!isset($parseURL['host']) || !isset($parseURL['scheme']) || !\in_array($parseURL['scheme'], ['http', 'https'], true)){ |
|
138 | + if (!isset($parseURL['host']) || !isset($parseURL['scheme']) || !\in_array($parseURL['scheme'], ['http', 'https'], true)) { |
|
139 | 139 | throw new ProviderException('getSignature: invalid url'); |
140 | 140 | } |
141 | 141 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | $signatureParams = \array_merge($query, $params); |
145 | 145 | |
146 | - if(isset($signatureParams['oauth_signature'])){ |
|
146 | + if (isset($signatureParams['oauth_signature'])) { |
|
147 | 147 | unset($signatureParams['oauth_signature']); |
148 | 148 | } |
149 | 149 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | $token->accessTokenSecret |
202 | 202 | ); |
203 | 203 | |
204 | - if(isset($query['oauth_session_handle'])){ |
|
204 | + if (isset($query['oauth_session_handle'])) { |
|
205 | 205 | $parameters['oauth_session_handle'] = $query['oauth_session_handle']; // @codeCoverageIgnore |
206 | 206 | } |
207 | 207 |
@@ -81,11 +81,9 @@ |
||
81 | 81 | |
82 | 82 | if(!$data || !\is_array($data)){ |
83 | 83 | throw new ProviderException('unable to parse token response'); |
84 | - } |
|
85 | - elseif(isset($data['error'])){ |
|
84 | + } elseif(isset($data['error'])){ |
|
86 | 85 | throw new ProviderException('error retrieving access token: '.$data['error']); |
87 | - } |
|
88 | - elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
86 | + } elseif(!isset($data['oauth_token']) || !isset($data['oauth_token_secret'])){ |
|
89 | 87 | throw new ProviderException('invalid token'); |
90 | 88 | } |
91 | 89 |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @property string $serviceName |
19 | 19 | * @property \chillerlan\OAuth\Storage\OAuthStorageInterface $storage |
20 | 20 | */ |
21 | -trait OAuth2CSRFTokenTrait{ |
|
21 | +trait OAuth2CSRFTokenTrait { |
|
22 | 22 | |
23 | 23 | /** |
24 | 24 | * @param string|null $state |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | */ |
29 | 29 | protected function checkState(string $state = null):void{ |
30 | 30 | |
31 | - if(empty($state) || !$this->storage->hasCSRFState($this->serviceName)){ |
|
31 | + if (empty($state) || !$this->storage->hasCSRFState($this->serviceName)) { |
|
32 | 32 | throw new ProviderException('invalid state for '.$this->serviceName); |
33 | 33 | } |
34 | 34 | |
35 | 35 | $knownState = $this->storage->getCSRFState($this->serviceName); |
36 | 36 | |
37 | - if(!\hash_equals($knownState, $state)){ |
|
37 | + if (!\hash_equals($knownState, $state)) { |
|
38 | 38 | throw new ProviderException('invalid CSRF state: '.$this->serviceName.' '.$state); |
39 | 39 | } |
40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | protected function setState(array $params):array{ |
49 | 49 | |
50 | - if(!isset($params['state'])){ |
|
50 | + if (!isset($params['state'])) { |
|
51 | 51 | $params['state'] = \sha1(\random_bytes(256)); |
52 | 52 | } |
53 | 53 |
@@ -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 |
@@ -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 string |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param \chillerlan\Settings\SettingsContainerInterface|null $options |
34 | 34 | */ |
35 | - public function __construct(SettingsContainerInterface $options = null){ |
|
35 | + public function __construct(SettingsContainerInterface $options = null) { |
|
36 | 36 | parent::__construct($options); |
37 | 37 | |
38 | 38 | $this->sessionVar = $this->options->sessionTokenVar; |
@@ -40,15 +40,15 @@ discard block |
||
40 | 40 | |
41 | 41 | // Determine if the session has started. |
42 | 42 | // @link http://stackoverflow.com/a/18542272/1470961 |
43 | - if($this->options->sessionStart && !(\session_status() !== \PHP_SESSION_NONE)){ |
|
43 | + if ($this->options->sessionStart && !(\session_status() !== \PHP_SESSION_NONE)) { |
|
44 | 44 | \session_start(); |
45 | 45 | } |
46 | 46 | |
47 | - if(!isset($_SESSION[$this->sessionVar])){ |
|
47 | + if (!isset($_SESSION[$this->sessionVar])) { |
|
48 | 48 | $_SESSION[$this->sessionVar] = []; |
49 | 49 | } |
50 | 50 | |
51 | - if(!isset($_SESSION[$this->stateVar])){ |
|
51 | + if (!isset($_SESSION[$this->stateVar])) { |
|
52 | 52 | $_SESSION[$this->stateVar] = []; |
53 | 53 | } |
54 | 54 | |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @codeCoverageIgnore |
61 | 61 | */ |
62 | - public function __destruct(){ |
|
63 | - if($this->options->sessionStart){ |
|
62 | + public function __destruct() { |
|
63 | + if ($this->options->sessionStart) { |
|
64 | 64 | \session_write_close(); |
65 | 65 | } |
66 | 66 | } |
@@ -74,10 +74,10 @@ discard block |
||
74 | 74 | public function storeAccessToken(string $service, AccessToken $token):OAuthStorageInterface{ |
75 | 75 | $data = $this->toStorage($token); |
76 | 76 | |
77 | - if(isset($_SESSION[$this->sessionVar]) && \is_array($_SESSION[$this->sessionVar])){ |
|
77 | + if (isset($_SESSION[$this->sessionVar]) && \is_array($_SESSION[$this->sessionVar])) { |
|
78 | 78 | $_SESSION[$this->sessionVar][$service] = $data; |
79 | 79 | } |
80 | - else{ |
|
80 | + else { |
|
81 | 81 | $_SESSION[$this->sessionVar] = [$service => $data]; |
82 | 82 | } |
83 | 83 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | public function getAccessToken(string $service):AccessToken{ |
94 | 94 | |
95 | - if($this->hasAccessToken($service)){ |
|
95 | + if ($this->hasAccessToken($service)) { |
|
96 | 96 | return $this->fromStorage($_SESSION[$this->sessionVar][$service]); |
97 | 97 | } |
98 | 98 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | */ |
116 | 116 | public function clearAccessToken(string $service):OAuthStorageInterface{ |
117 | 117 | |
118 | - if(\array_key_exists($service, $_SESSION[$this->sessionVar])){ |
|
118 | + if (\array_key_exists($service, $_SESSION[$this->sessionVar])) { |
|
119 | 119 | unset($_SESSION[$this->sessionVar][$service]); |
120 | 120 | } |
121 | 121 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function clearAllAccessTokens():OAuthStorageInterface{ |
129 | 129 | |
130 | - foreach(\array_keys($_SESSION[$this->sessionVar]) as $service){ |
|
130 | + foreach (\array_keys($_SESSION[$this->sessionVar]) as $service) { |
|
131 | 131 | unset($_SESSION[$this->sessionVar][$service]); |
132 | 132 | } |
133 | 133 | |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function storeCSRFState(string $service, string $state):OAuthStorageInterface{ |
146 | 146 | |
147 | - if(isset($_SESSION[$this->stateVar]) && \is_array($_SESSION[$this->stateVar])){ |
|
147 | + if (isset($_SESSION[$this->stateVar]) && \is_array($_SESSION[$this->stateVar])) { |
|
148 | 148 | $_SESSION[$this->stateVar][$service] = $state; |
149 | 149 | } |
150 | - else{ |
|
150 | + else { |
|
151 | 151 | $_SESSION[$this->stateVar] = [$service => $state]; |
152 | 152 | } |
153 | 153 | |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function getCSRFState(string $service):string{ |
164 | 164 | |
165 | - if($this->hasCSRFState($service)){ |
|
165 | + if ($this->hasCSRFState($service)) { |
|
166 | 166 | return $_SESSION[$this->stateVar][$service]; |
167 | 167 | } |
168 | 168 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | */ |
186 | 186 | public function clearCSRFState(string $service):OAuthStorageInterface{ |
187 | 187 | |
188 | - if(\array_key_exists($service, $_SESSION[$this->stateVar])){ |
|
188 | + if (\array_key_exists($service, $_SESSION[$this->stateVar])) { |
|
189 | 189 | unset($_SESSION[$this->stateVar][$service]); |
190 | 190 | } |
191 | 191 |
@@ -76,8 +76,7 @@ discard block |
||
76 | 76 | |
77 | 77 | if(isset($_SESSION[$this->sessionVar]) && \is_array($_SESSION[$this->sessionVar])){ |
78 | 78 | $_SESSION[$this->sessionVar][$service] = $data; |
79 | - } |
|
80 | - else{ |
|
79 | + } else{ |
|
81 | 80 | $_SESSION[$this->sessionVar] = [$service => $data]; |
82 | 81 | } |
83 | 82 | |
@@ -146,8 +145,7 @@ discard block |
||
146 | 145 | |
147 | 146 | if(isset($_SESSION[$this->stateVar]) && \is_array($_SESSION[$this->stateVar])){ |
148 | 147 | $_SESSION[$this->stateVar][$service] = $state; |
149 | - } |
|
150 | - else{ |
|
148 | + } else{ |
|
151 | 149 | $_SESSION[$this->stateVar] = [$service => $state]; |
152 | 150 | } |
153 | 151 |
@@ -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]); |
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 |