Skip to content

Commit 6d3c1d0

Browse files
committed
Cleaned up code after Mago code analysis
1 parent 292819b commit 6d3c1d0

3 files changed

Lines changed: 25 additions & 10 deletions

File tree

Taskfile.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ tasks:
2929
- task: coding-standards:composer:apply
3030
- task: coding-standards:markdown:apply
3131
- task: coding-standards:php:apply
32+
- task: coding-standards:php:mago:apply
3233
- task: coding-standards:yaml:apply
3334

3435
coding-standards:check:
3536
- task: coding-standards:composer:check
3637
- task: coding-standards:markdown:check
3738
- task: coding-standards:php:check
39+
- task: coding-standards:php:mago:check
3840
- task: coding-standards:yaml:check
3941

4042
coding-standards:composer:apply:
@@ -73,6 +75,17 @@ tasks:
7375
vars:
7476
TASK_ARGS: run --rm phpfpm vendor/bin/php-cs-fixer fix --dry-run --diff
7577

78+
coding-standards:php:mago:apply:
79+
- task: compose
80+
vars:
81+
TASK_ARGS: run --rm mago format
82+
83+
coding-standards:php:mago:check:
84+
- task: coding-standards:php:mago:apply
85+
- task: compose
86+
vars:
87+
TASK_ARGS: run --rm mago lint
88+
7689
coding-standards:yaml:apply:
7790
- task: compose
7891
vars:

src/Client/ApiClient.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
* @phpstan-type AccessToken array{access_token: string, token_type: string, expires_in: int, refresh_token: string}
2929
* @phpstan-type ServiceIndex array<string, array{href: string, title: string}>
3030
* @phpstan-type OptionsInput array{
31-
* api_uri: non-empty-string,
32-
* api_username: non-empty-string,
33-
* api_secret: non-empty-string,
34-
* f2_username: non-empty-string,
31+
* api_uri: string,
32+
* api_username: string,
33+
* api_secret: string,
34+
* f2_username: string,
3535
* cache_item_pool: CacheItemPoolInterface,
3636
* cache_item_lifetime?: int,
3737
* }
38-
* @phpstan-type Options array{
38+
* @phpstan-type OptionsResolved array{
3939
* api_uri: non-empty-string,
4040
* api_username: non-empty-string,
4141
* api_secret: non-empty-string,
@@ -48,7 +48,7 @@ class ApiClient
4848
use LoggerAwareTrait;
4949
use LoggerTrait;
5050

51-
/** @var Options */
51+
/** @var OptionsResolved */
5252
private readonly array $options;
5353

5454
private ?HttpClientInterface $client = null;
@@ -61,7 +61,9 @@ public function __construct(array $options)
6161
$resolver = new OptionsResolver();
6262
$this->configureOptions($resolver);
6363

64-
$this->options = $resolver->resolve($options);
64+
/** @var OptionsResolved $options */
65+
$options = $resolver->resolve($options);
66+
$this->options = $options;
6567
}
6668

6769
/**
@@ -78,6 +80,7 @@ public function getServiceIndex(): array
7880
$cache = $this->getCache();
7981
$cacheKey = sha1(__METHOD__);
8082

83+
// @mago-ignore analysis:less-specific-return-statement
8184
return $cache->get($cacheKey, function (CacheItemInterface $item): array {
8285
$item->expiresAfter((int) $this->options['cache_item_lifetime']);
8386

@@ -455,7 +458,6 @@ function (array $matches) use ($url, $values): string {
455458

456459
protected function getCache(): CacheInterface
457460
{
458-
/** @var CacheItemPoolInterface $pool */
459461
$pool = $this->options['cache_item_pool'];
460462

461463
return new ProxyAdapter(pool: $pool);
@@ -491,7 +493,7 @@ protected function createItemResult(ResponseInterface $response, string $class):
491493
{
492494
$item = new \SimpleXMLElement($response->getContent());
493495

494-
/* @var T */
496+
// @mago-ignore analysis:invalid-return-statement
495497
return $class::fromSimpleXMLElement($item);
496498
}
497499

src/Command/F2ApiClientCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private function createClient(?string $cacheDirectory): ApiClient
8282
}
8383

8484
/**
85-
* @return array<string, mixed>
85+
* @return array<array-key, mixed>
8686
*/
8787
private function responseToArray(array|AbstractItem $response): array
8888
{

0 commit comments

Comments
 (0)