Passed
Push — main ( e41c5f...8f9259 )
by smiley
09:50
created
src/Core/OAuthProvider.php 2 patches
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -335,12 +335,10 @@
 block discarded – undo
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
 			}
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  * @property string                                          $serviceName
44 44
  * @property string|null                                     $userRevokeURL
45 45
  */
46
-abstract class OAuthProvider implements OAuthInterface{
46
+abstract class OAuthProvider implements OAuthInterface {
47 47
 	use LoggerAwareTrait;
48 48
 
49 49
 	protected const ALLOWED_PROPERTIES = [
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 		OAuthStorageInterface $storage,
158 158
 		SettingsContainerInterface $options,
159 159
 		LoggerInterface $logger = null
160
-	){
160
+	) {
161 161
 		$this->http    = $http;
162 162
 		$this->storage = $storage;
163 163
 		$this->options = $options;
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 
170 170
 		$this->serviceName = (new ReflectionClass($this))->getShortName();
171 171
 
172
-		if(!empty($this->endpointMap) && class_exists($this->endpointMap)){
172
+		if (!empty($this->endpointMap) && class_exists($this->endpointMap)) {
173 173
 			$this->endpoints = new $this->endpointMap;
174 174
 
175
-			if(!$this->endpoints instanceof EndpointMapInterface){
175
+			if (!$this->endpoints instanceof EndpointMapInterface) {
176 176
 				throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore
177 177
 			}
178 178
 
@@ -187,9 +187,9 @@  discard block
 block discarded – undo
187 187
 	 *
188 188
 	 * @return mixed|null
189 189
 	 */
190
-	public function __get(string $name){
190
+	public function __get(string $name) {
191 191
 
192
-		if(in_array($name, $this::ALLOWED_PROPERTIES, true)){
192
+		if (in_array($name, $this::ALLOWED_PROPERTIES, true)) {
193 193
 			return $this->{$name};
194 194
 		}
195 195
 
@@ -247,11 +247,11 @@  discard block
 block discarded – undo
247 247
 	 */
248 248
 	public function __call(string $endpointName, array $arguments):ResponseInterface{
249 249
 
250
-		if(!$this->endpoints instanceof EndpointMap){
250
+		if (!$this->endpoints instanceof EndpointMap) {
251 251
 			throw new ApiClientException('MagicAPI not available'); // @codeCoverageIgnore
252 252
 		}
253 253
 
254
-		if(!isset($this->endpoints->{$endpointName})){
254
+		if (!isset($this->endpoints->{$endpointName})) {
255 255
 			throw new ApiClientException('endpoint not found: "'.$endpointName.'"');
256 256
 		}
257 257
 
@@ -271,25 +271,25 @@  discard block
 block discarded – undo
271 271
 		$path_element_count = count($path_elements);
272 272
 		$query_param_count  = count($query_params);
273 273
 
274
-		if($path_element_count > 0){
274
+		if ($path_element_count > 0) {
275 275
 			$path = $this->parsePathElements($path, $path_elements, $path_element_count, $arguments);
276 276
 		}
277 277
 
278
-		if($query_param_count > 0){
278
+		if ($query_param_count > 0) {
279 279
 			// $params is the first argument after path segments
280 280
 			$params = $arguments[$path_element_count] ?? null;
281 281
 
282
-			if(is_array($params)){
282
+			if (is_array($params)) {
283 283
 				$params = $this->cleanQueryParams($this->removeUnlistedParams($params, $query_params));
284 284
 			}
285 285
 		}
286 286
 
287
-		if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body){
287
+		if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body) {
288 288
 			// if no query params are present, $body is the first argument after any path segments
289 289
 			$argPos = $query_param_count > 0 ? 1 : 0;
290 290
 			$body   = $arguments[$path_element_count + $argPos] ?? null;
291 291
 
292
-			if(is_array($body)){
292
+			if (is_array($body)) {
293 293
 				$body = $this->cleanBodyParams($body);
294 294
 			}
295 295
 		}
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 		// we don't know if all of the given arguments are path elements...
311 311
 		$urlparams = array_slice($arguments, 0, $path_element_count);
312 312
 
313
-		if(count($urlparams) !== $path_element_count){
313
+		if (count($urlparams) !== $path_element_count) {
314 314
 			throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements));
315 315
 		}
316 316
 
317
-		foreach($urlparams as $i => $param){
317
+		foreach ($urlparams as $i => $param) {
318 318
 			// ...but we do know that the arguments after the path elements are usually array or null
319
-			if(!is_scalar($param)){
319
+			if (!is_scalar($param)) {
320 320
 				$msg = 'invalid path element value for "%s": %s';
321 321
 
322 322
 				throw new APIClientException(sprintf($msg, $path_elements[$i], var_export($param, true)));
@@ -332,9 +332,9 @@  discard block
 block discarded – undo
332 332
 	protected function removeUnlistedParams(array $params, array $allowed):array{
333 333
 		$query = [];
334 334
 		// remove any params that are not listed
335
-		foreach($params as $key => $value){
335
+		foreach ($params as $key => $value) {
336 336
 
337
-			if(!in_array($key, $allowed, true)){
337
+			if (!in_array($key, $allowed, true)) {
338 338
 				continue;
339 339
 			}
340 340
 
@@ -372,28 +372,28 @@  discard block
 block discarded – undo
372 372
 		$request = $this->requestFactory
373 373
 			->createRequest($method ?? 'GET', merge_query($this->getRequestTarget($path), $params ?? []));
374 374
 
375
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
375
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
376 376
 			$request = $request->withAddedHeader($header, $value);
377 377
 		}
378 378
 
379
-		if($request->hasHeader('content-type')){
379
+		if ($request->hasHeader('content-type')) {
380 380
 			$contentType = strtolower($request->getHeaderLine('content-type'));
381 381
 
382
-			if(is_array($body)){
383
-				if($contentType === 'application/x-www-form-urlencoded'){
382
+			if (is_array($body)) {
383
+				if ($contentType === 'application/x-www-form-urlencoded') {
384 384
 					$body = $this->streamFactory->createStream(http_build_query($body, '', '&', PHP_QUERY_RFC1738));
385 385
 				}
386
-				elseif($contentType === 'application/json' || $contentType === 'application/vnd.api+json'){
386
+				elseif ($contentType === 'application/json' || $contentType === 'application/vnd.api+json') {
387 387
 					$body = $this->streamFactory->createStream(json_encode($body));
388 388
 				}
389 389
 			}
390
-			elseif(is_string($body)){
390
+			elseif (is_string($body)) {
391 391
 				// we don't check if the given string matches the content type - this is the implementor's responsibility
392 392
 				$body = $this->streamFactory->createStream($body);
393 393
 			}
394 394
 		}
395 395
 
396
-		if($body instanceof StreamInterface){
396
+		if ($body instanceof StreamInterface) {
397 397
 			$request = $request
398 398
 				->withBody($body)
399 399
 				->withHeader('Content-length', (string)$body->getSize())
@@ -415,15 +415,15 @@  discard block
 block discarded – undo
415 415
 	protected function getRequestTarget(string $uri):string{
416 416
 		$parsedURL = parse_url($uri);
417 417
 
418
-		if(!isset($parsedURL['path'])){
418
+		if (!isset($parsedURL['path'])) {
419 419
 			throw new ProviderException('invalid path');
420 420
 		}
421 421
 
422 422
 		// for some reason we were given a host name
423
-		if(isset($parsedURL['host'])){
423
+		if (isset($parsedURL['host'])) {
424 424
 
425 425
 			// back out if it doesn't match
426
-			if($parsedURL['host'] !== parse_url($this->apiURL, PHP_URL_HOST)){
426
+			if ($parsedURL['host'] !== parse_url($this->apiURL, PHP_URL_HOST)) {
427 427
 				throw new ProviderException('given host does not match provider host');
428 428
 			}
429 429
 
@@ -441,15 +441,15 @@  discard block
 block discarded – undo
441 441
 	public function sendRequest(RequestInterface $request):ResponseInterface{
442 442
 
443 443
 		// get authorization only if we request the provider API
444
-		if(strpos((string)$request->getUri(), $this->apiURL) === 0){
444
+		if (strpos((string)$request->getUri(), $this->apiURL) === 0) {
445 445
 			$token = $this->storage->getAccessToken($this->serviceName);
446 446
 
447 447
 			// attempt to refresh an expired token
448
-			if(
448
+			if (
449 449
 				$this instanceof TokenRefresh
450 450
 				&& $this->options->tokenAutoRefresh
451 451
 				&& ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)
452
-			){
452
+			) {
453 453
 				$token = $this->refreshAccessToken($token);
454 454
 			}
455 455
 
Please login to merge, or discard this patch.
src/OAuthOptionsTrait.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Storage/OAuthStorageInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Storage/MemoryStorage.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Storage/OAuthStorageAbstract.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Storage/SessionStorage.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Core/TokenRefresh.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
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.
Please login to merge, or discard this patch.
src/Core/ClientCredentials.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
src/Core/OAuth1Interface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
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.
Please login to merge, or discard this patch.