Skip to content

Commit c7e463c

Browse files
committed
Refactor code according PHPStan rules
1 parent 7aba299 commit c7e463c

File tree

16 files changed

+81
-35
lines changed

16 files changed

+81
-35
lines changed

phpstan.neon

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ parameters:
55
excludePaths:
66
- src/Core/Infrastructure/Symfony/Kernel.php
77
ignoreErrors:
8-
- '/^Method Panda\\\w+\\Infrastructure\\ApiState\\Processor\\\w+Processor::process\(\) has no return type specified\.$/'
9-
- '/^Method Panda\\\w+\\Infrastructure\\ApiState\\Processor\\\w+Processor::process\(\) has parameter \$(context|uriVariables) with no value type specified in iterable type array\.$/'
10-
- '/^Method Panda\\\w+\\Infrastructure\\ApiState\\Processor\\\w+Processor::process\(\) has parameter \$data with no type specified\.$/'
11-
- '/^Method Panda\\\w+\\Infrastructure\\ApiState\\Provider\\\w+Provider::provide\(\) has parameter \$(context|uriVariables) with no value type specified in iterable type array\.$/'
128
- '/^Method Panda\\\w+\\Infrastructure\\ApiSerializer\\\w+Normalizer::normalize\(\) has parameter \$context with no value type specified in iterable type array\.$/'
139
- '/^Method Panda\\\w+\\Infrastructure\\ApiSerializer\\\w+Normalizer::supportsNormalization\(\) has parameter \$context with no value type specified in iterable type array\.$/'
1410
- '/^Method Panda\\\w+\\Infrastructure\\ApiSerializer\\\w+Normalizer::normalize\(\) return type has no value type specified in iterable type array\.$/'
@@ -18,8 +14,8 @@ parameters:
1814
-
1915
message: '/^Generator expects value type object, mixed given\.$/'
2016
path: src/Core/Infrastructure/Doctrine/Orm/DoctrineCollectionIterator.php
21-
22-
checkGenericClassInNonGenericObjectType: false
17+
-
18+
identifier: missingType.generics
2319

2420
services:
2521
-

src/Account/Infrastructure/ApiState/Provider/UserProvider.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Panda\Account\Domain\Model\User;
1111
use Panda\Account\Infrastructure\ApiResource\UserResource;
1212
use Panda\Core\Application\Query\QueryBusInterface;
13+
use Symfony\Component\Uid\Uuid;
14+
use Webmozart\Assert\Assert;
1315

1416
final readonly class UserProvider implements ProviderInterface
1517
{
@@ -19,8 +21,10 @@ public function __construct(private QueryBusInterface $queryBus)
1921

2022
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?UserResource
2123
{
24+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
25+
2226
/** @var User|null $model */
23-
$model = $this->queryBus->ask(new FindUserQuery($uriVariables['id']));
27+
$model = $this->queryBus->ask(new FindUserQuery($id));
2428

2529
if (null === $model) {
2630
return null;

src/Exchange/Infrastructure/ApiState/Processor/ExchangeRateLiveProcessor.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Panda\Exchange\Application\Command\ExchangeRateLive\UpdateExchangeRateLiveCommand;
1414
use Panda\Exchange\Domain\Model\ExchangeRateLiveInterface;
1515
use Panda\Exchange\Infrastructure\ApiResource\ExchangeRateLiveResource;
16+
use Symfony\Component\Uid\Uuid;
1617
use Webmozart\Assert\Assert;
1718

1819
final readonly class ExchangeRateLiveProcessor implements ProcessorInterface
@@ -27,18 +28,22 @@ public function process($data, Operation $operation, array $uriVariables = [], a
2728
Assert::isInstanceOf($data, ExchangeRateLiveResource::class);
2829

2930
if ($operation instanceof DeleteOperationInterface) {
30-
$this->commandBus->dispatch(new DeleteExchangeRateLiveCommand($uriVariables['id']));
31+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
32+
33+
$this->commandBus->dispatch(new DeleteExchangeRateLiveCommand($id));
3134

3235
return null;
3336
}
3437

35-
$command = !isset($uriVariables['id'])
38+
Assert::nullOrIsInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
39+
40+
$command = null === $id
3641
? new CreateExchangeRateLiveCommand(
3742
(string) $data->baseTicker,
3843
(string) $data->quoteTicker,
3944
(float) $data->rate,
4045
)
41-
: new UpdateExchangeRateLiveCommand($uriVariables['id'], (float) $data->rate);
46+
: new UpdateExchangeRateLiveCommand($id, (float) $data->rate);
4247

4348
/** @var ExchangeRateLiveInterface $model */
4449
$model = $this->commandBus->dispatch($command);

src/Exchange/Infrastructure/ApiState/Processor/ExchangeRateLogProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Panda\Exchange\Application\Command\ExchangeRateLog\DeleteExchangeRateLogCommand;
1313
use Panda\Exchange\Domain\Model\ExchangeRateLogInterface;
1414
use Panda\Exchange\Infrastructure\ApiResource\ExchangeRateLogResource;
15+
use Symfony\Component\Uid\Uuid;
1516
use Webmozart\Assert\Assert;
1617

1718
final readonly class ExchangeRateLogProcessor implements ProcessorInterface
@@ -26,7 +27,9 @@ public function process($data, Operation $operation, array $uriVariables = [], a
2627
Assert::isInstanceOf($data, ExchangeRateLogResource::class);
2728

2829
if ($operation instanceof DeleteOperationInterface) {
29-
$this->commandBus->dispatch(new DeleteExchangeRateLogCommand($uriVariables['id']));
30+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
31+
32+
$this->commandBus->dispatch(new DeleteExchangeRateLogCommand($id));
3033

3134
return null;
3235
}

src/Exchange/Infrastructure/ApiState/Provider/ExchangeRateLiveProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Panda\Exchange\Domain\Model\ExchangeRateLive;
1717
use Panda\Exchange\Infrastructure\ApiResource\ExchangeRateLiveResource;
1818
use Symfony\Component\Uid\Uuid;
19+
use Webmozart\Assert\Assert;
1920

2021
final readonly class ExchangeRateLiveProvider implements ProviderInterface
2122
{
@@ -31,7 +32,9 @@ public function __construct(
3132
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
3233
{
3334
if (!$operation instanceof CollectionOperationInterface) {
34-
return $this->provideItem($uriVariables['id']);
35+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
36+
37+
return $this->provideItem($id);
3538
}
3639

3740
$offset = $limit = null;
@@ -41,10 +44,14 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4144
$limit = $this->pagination->getLimit($operation, $context);
4245
}
4346

47+
/** @phpstan-ignore-next-line false positive */
4448
$baseTicker = isset($context['filters']['baseTicker'])
49+
/** @phpstan-ignore-next-line false positive */
4550
? (string) $context['filters']['baseTicker']
4651
: null;
52+
/** @phpstan-ignore-next-line false positive */
4753
$quoteTicker = isset($context['filters']['quoteTicker'])
54+
/** @phpstan-ignore-next-line false positive */
4855
? (string) $context['filters']['quoteTicker']
4956
: null;
5057

src/Exchange/Infrastructure/ApiState/Provider/ExchangeRateLogProvider.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Panda\Exchange\Domain\Model\ExchangeRateLog;
1717
use Panda\Exchange\Infrastructure\ApiResource\ExchangeRateLogResource;
1818
use Symfony\Component\Uid\Uuid;
19+
use Webmozart\Assert\Assert;
1920

2021
final readonly class ExchangeRateLogProvider implements ProviderInterface
2122
{
@@ -31,7 +32,9 @@ public function __construct(
3132
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
3233
{
3334
if (!$operation instanceof CollectionOperationInterface) {
34-
return $this->provideItem($uriVariables['id']);
35+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
36+
37+
return $this->provideItem($id);
3538
}
3639

3740
$offset = $limit = null;
@@ -41,10 +44,14 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
4144
$limit = $this->pagination->getLimit($operation, $context);
4245
}
4346

47+
/** @phpstan-ignore-next-line false positive */
4448
$baseTicker = isset($context['filters']['baseTicker'])
49+
/** @phpstan-ignore-next-line false positive */
4550
? (string) $context['filters']['baseTicker']
4651
: null;
52+
/** @phpstan-ignore-next-line false positive */
4753
$quoteTicker = isset($context['filters']['quoteTicker'])
54+
/** @phpstan-ignore-next-line false positive */
4855
? (string) $context['filters']['quoteTicker']
4956
: null;
5057

src/Portfolio/Infrastructure/ApiSerializer/InResourceRepresentationNormalizer.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ public function supportsNormalization(mixed $data, ?string $format = null, array
5151
;
5252
}
5353

54-
// public function getSupportedTypes(?string $format): array
55-
// {
56-
// return [
57-
// ResourceRepresentation::class => true,
58-
// QuantityRepresentation::class => true,
59-
// ReportEntryRepresentation::class => true,
60-
// ReportFileRepresentation::class => true,
61-
// ];
62-
// }
54+
// public function getSupportedTypes(?string $format): array
55+
// {
56+
// return [
57+
// ResourceRepresentation::class => true,
58+
// QuantityRepresentation::class => true,
59+
// ReportEntryRepresentation::class => true,
60+
// ReportFileRepresentation::class => true,
61+
// ];
62+
// }
6363
}

src/Portfolio/Infrastructure/ApiState/Processor/PortfolioChangeDefaultProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Panda\Portfolio\Application\Command\Portfolio\ChangeDefaultPortfolioCommand;
1111
use Panda\Portfolio\Domain\Model\Portfolio\PortfolioInterface;
1212
use Panda\Portfolio\Infrastructure\ApiResource\PortfolioResource;
13+
use Symfony\Component\Uid\Uuid;
1314
use Webmozart\Assert\Assert;
1415

1516
final readonly class PortfolioChangeDefaultProcessor implements ProcessorInterface
@@ -22,8 +23,9 @@ public function process($data, Operation $operation, array $uriVariables = [], a
2223
{
2324
/** @var PortfolioResource $data */
2425
Assert::isInstanceOf($data, PortfolioResource::class);
26+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
2527

26-
$command = new ChangeDefaultPortfolioCommand($uriVariables['id']);
28+
$command = new ChangeDefaultPortfolioCommand($id);
2729

2830
/** @var PortfolioInterface $model */
2931
$model = $this->commandBus->dispatch($command);

src/Portfolio/Infrastructure/ApiState/Processor/PortfolioUpdateProcessor.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Panda\Portfolio\Application\Command\Portfolio\UpdatePortfolioCommand;
1111
use Panda\Portfolio\Domain\Model\Portfolio\PortfolioInterface;
1212
use Panda\Portfolio\Infrastructure\ApiResource\PortfolioResource;
13+
use Symfony\Component\Uid\Uuid;
1314
use Webmozart\Assert\Assert;
1415

1516
final readonly class PortfolioUpdateProcessor implements ProcessorInterface
@@ -22,8 +23,9 @@ public function process($data, Operation $operation, array $uriVariables = [], a
2223
{
2324
/** @var PortfolioResource $data */
2425
Assert::isInstanceOf($data, PortfolioResource::class);
26+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
2527

26-
$command = new UpdatePortfolioCommand($uriVariables['id'], (string) $data->name);
28+
$command = new UpdatePortfolioCommand($id, (string) $data->name);
2729

2830
/** @var PortfolioInterface $model */
2931
$model = $this->commandBus->dispatch($command);

src/Portfolio/Infrastructure/ApiState/Provider/PortfolioProvider.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Panda\Portfolio\Domain\Model\Portfolio\Portfolio;
1717
use Panda\Portfolio\Infrastructure\ApiResource\PortfolioResource;
1818
use Symfony\Component\Uid\Uuid;
19+
use Webmozart\Assert\Assert;
1920

2021
final readonly class PortfolioProvider implements ProviderInterface
2122
{
@@ -31,7 +32,9 @@ public function __construct(
3132
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
3233
{
3334
if (!$operation instanceof CollectionOperationInterface) {
34-
return $this->provideItem($uriVariables['id']);
35+
Assert::isInstanceOf($id = $uriVariables['id'] ?? null, Uuid::class);
36+
37+
return $this->provideItem($id);
3538
}
3639

3740
$offset = $limit = null;

0 commit comments

Comments
 (0)