Passed
Push — main ( d8887d...0218a6 )
by smiley
01:57
created
src/Core/OAuthProvider.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
  * @property string                                          $serviceName
42 42
  * @property string|null                                     $userRevokeURL
43 43
  */
44
-abstract class OAuthProvider implements OAuthInterface{
44
+abstract class OAuthProvider implements OAuthInterface {
45 45
 	use LoggerAwareTrait;
46 46
 
47 47
 	protected const ALLOWED_PROPERTIES = [
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 		OAuthStorageInterface $storage,
151 151
 		SettingsContainerInterface $options,
152 152
 		LoggerInterface $logger = null
153
-	){
153
+	) {
154 154
 		$this->http    = $http;
155 155
 		$this->storage = $storage;
156 156
 		$this->options = $options;
@@ -164,10 +164,10 @@  discard block
 block discarded – undo
164 164
 
165 165
 		$this->serviceName = (new ReflectionClass($this))->getShortName();
166 166
 
167
-		if(!empty($this->endpointMap) && class_exists($this->endpointMap)){
167
+		if (!empty($this->endpointMap) && class_exists($this->endpointMap)) {
168 168
 			$this->endpoints = new $this->endpointMap;
169 169
 
170
-			if(!$this->endpoints instanceof EndpointMapInterface){
170
+			if (!$this->endpoints instanceof EndpointMapInterface) {
171 171
 				throw new ApiClientException('invalid endpoint map'); // @codeCoverageIgnore
172 172
 			}
173 173
 
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 */
183 183
 	public function __get(string $name):mixed{
184 184
 
185
-		if(in_array($name, $this::ALLOWED_PROPERTIES, true)){
185
+		if (in_array($name, $this::ALLOWED_PROPERTIES, true)) {
186 186
 			return $this->{$name};
187 187
 		}
188 188
 
@@ -251,11 +251,11 @@  discard block
 block discarded – undo
251 251
 	 */
252 252
 	public function __call(string $endpointName, array $arguments):ResponseInterface{
253 253
 
254
-		if(!$this->endpoints instanceof EndpointMap){
254
+		if (!$this->endpoints instanceof EndpointMap) {
255 255
 			throw new ApiClientException('MagicAPI not available'); // @codeCoverageIgnore
256 256
 		}
257 257
 
258
-		if(!isset($this->endpoints->{$endpointName})){
258
+		if (!isset($this->endpoints->{$endpointName})) {
259 259
 			throw new ApiClientException('endpoint not found: "'.$endpointName.'"');
260 260
 		}
261 261
 
@@ -275,25 +275,25 @@  discard block
 block discarded – undo
275 275
 		$path_element_count = count($path_elements);
276 276
 		$query_param_count  = count($query_params);
277 277
 
278
-		if($path_element_count > 0){
278
+		if ($path_element_count > 0) {
279 279
 			$path = $this->parsePathElements($path, $path_elements, $path_element_count, $arguments);
280 280
 		}
281 281
 
282
-		if($query_param_count > 0){
282
+		if ($query_param_count > 0) {
283 283
 			// $params is the first argument after path segments
284 284
 			$params = $arguments[$path_element_count] ?? null;
285 285
 
286
-			if(is_array($params)){
286
+			if (is_array($params)) {
287 287
 				$params = $this->cleanQueryParams($this->removeUnlistedParams($params, $query_params));
288 288
 			}
289 289
 		}
290 290
 
291
-		if(in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body){
291
+		if (in_array($method, ['POST', 'PATCH', 'PUT', 'DELETE']) && $has_body) {
292 292
 			// if no query params are present, $body is the first argument after any path segments
293 293
 			$argPos = $query_param_count > 0 ? 1 : 0;
294 294
 			$body   = $arguments[$path_element_count + $argPos] ?? null;
295 295
 
296
-			if(is_array($body)){
296
+			if (is_array($body)) {
297 297
 				$body = $this->cleanBodyParams($body);
298 298
 			}
299 299
 		}
@@ -314,13 +314,13 @@  discard block
 block discarded – undo
314 314
 		// we don't know if all of the given arguments are path elements...
315 315
 		$urlparams = array_slice($arguments, 0, $path_element_count);
316 316
 
317
-		if(count($urlparams) !== $path_element_count){
317
+		if (count($urlparams) !== $path_element_count) {
318 318
 			throw new APIClientException('too few URL params, required: '.implode(', ', $path_elements));
319 319
 		}
320 320
 
321
-		foreach($urlparams as $i => $param){
321
+		foreach ($urlparams as $i => $param) {
322 322
 			// ...but we do know that the arguments after the path elements are usually array or null
323
-			if(!is_scalar($param)){
323
+			if (!is_scalar($param)) {
324 324
 				$msg = 'invalid path element value for "%s": %s';
325 325
 
326 326
 				throw new APIClientException(sprintf($msg, $path_elements[$i], var_export($param, true)));
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
 	protected function removeUnlistedParams(array $params, array $allowed):array{
337 337
 		$query = [];
338 338
 		// remove any params that are not listed
339
-		foreach($params as $key => $value){
339
+		foreach ($params as $key => $value) {
340 340
 
341
-			if(!in_array($key, $allowed, true)){
341
+			if (!in_array($key, $allowed, true)) {
342 342
 				continue;
343 343
 			}
344 344
 
@@ -397,28 +397,28 @@  discard block
 block discarded – undo
397 397
 		$request = $this->requestFactory
398 398
 			->createRequest($method ?? 'GET', $this->mergeQuery($this->getRequestTarget($path), $params ?? []));
399 399
 
400
-		foreach(array_merge($this->apiHeaders, $headers ?? []) as $header => $value){
400
+		foreach (array_merge($this->apiHeaders, $headers ?? []) as $header => $value) {
401 401
 			$request = $request->withAddedHeader($header, $value);
402 402
 		}
403 403
 
404
-		if($request->hasHeader('content-type')){
404
+		if ($request->hasHeader('content-type')) {
405 405
 			$contentType = strtolower($request->getHeaderLine('content-type'));
406 406
 
407
-			if(is_array($body)){
408
-				if($contentType === 'application/x-www-form-urlencoded'){
407
+			if (is_array($body)) {
408
+				if ($contentType === 'application/x-www-form-urlencoded') {
409 409
 					$body = $this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738));
410 410
 				}
411
-				elseif(in_array($contentType, ['application/json', 'application/vnd.api+json'])){
411
+				elseif (in_array($contentType, ['application/json', 'application/vnd.api+json'])) {
412 412
 					$body = $this->streamFactory->createStream(json_encode($body));
413 413
 				}
414 414
 			}
415
-			elseif(is_string($body)){
415
+			elseif (is_string($body)) {
416 416
 				// we don't check if the given string matches the content type - this is the implementor's responsibility
417 417
 				$body = $this->streamFactory->createStream($body);
418 418
 			}
419 419
 		}
420 420
 
421
-		if($body instanceof StreamInterface){
421
+		if ($body instanceof StreamInterface) {
422 422
 			$request = $request
423 423
 				->withBody($body)
424 424
 				->withHeader('Content-length', (string)$body->getSize())
@@ -440,17 +440,17 @@  discard block
 block discarded – undo
440 440
 	protected function getRequestTarget(string $uri):string{
441 441
 		$parsedURL = QueryUtil::parseUrl($uri);
442 442
 
443
-		if(!isset($parsedURL['path'])){
443
+		if (!isset($parsedURL['path'])) {
444 444
 			throw new ProviderException('invalid path');
445 445
 		}
446 446
 
447 447
 		// for some reason we were given a host name
448
-		if(isset($parsedURL['host'])){
448
+		if (isset($parsedURL['host'])) {
449 449
 			$api  = QueryUtil::parseUrl($this->apiURL);
450 450
 			$host = $api['host'] ?? null;
451 451
 
452 452
 			// back out if it doesn't match
453
-			if($parsedURL['host'] !== $host){
453
+			if ($parsedURL['host'] !== $host) {
454 454
 				throw new ProviderException('given host does not match provider host');
455 455
 			}
456 456
 
@@ -468,15 +468,15 @@  discard block
 block discarded – undo
468 468
 	public function sendRequest(RequestInterface $request):ResponseInterface{
469 469
 
470 470
 		// get authorization only if we request the provider API
471
-		if(str_starts_with((string)$request->getUri(), $this->apiURL)){
471
+		if (str_starts_with((string)$request->getUri(), $this->apiURL)) {
472 472
 			$token = $this->storage->getAccessToken($this->serviceName);
473 473
 
474 474
 			// attempt to refresh an expired token
475
-			if(
475
+			if (
476 476
 				$this instanceof TokenRefresh
477 477
 				&& $this->options->tokenAutoRefresh
478 478
 				&& ($token->isExpired() || $token->expires === $token::EOL_UNKNOWN)
479
-			){
479
+			) {
480 480
 				$token = $this->refreshAccessToken($token);
481 481
 			}
482 482
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -407,12 +407,10 @@
 block discarded – undo
407 407
 			if(is_array($body)){
408 408
 				if($contentType === 'application/x-www-form-urlencoded'){
409 409
 					$body = $this->streamFactory->createStream($this->buildQuery($body, PHP_QUERY_RFC1738));
410
-				}
411
-				elseif(in_array($contentType, ['application/json', 'application/vnd.api+json'])){
410
+				} elseif(in_array($contentType, ['application/json', 'application/vnd.api+json'])){
412 411
 					$body = $this->streamFactory->createStream(json_encode($body));
413 412
 				}
414
-			}
415
-			elseif(is_string($body)){
413
+			} elseif(is_string($body)){
416 414
 				// we don't check if the given string matches the content type - this is the implementor's responsibility
417 415
 				$body = $this->streamFactory->createStream($body);
418 416
 			}
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
 	/**
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	/**
31 31
 	 * OAuthStorageAbstract constructor.
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);
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 	 */
52 52
 	public function fromStorage(mixed $data):AccessToken{
53 53
 
54
-		if(!is_string($data)){
54
+		if (!is_string($data)) {
55 55
 			throw new OAuthStorageException('invalid data');
56 56
 		}
57 57
 
Please login to merge, or discard this patch.