Skip to content

Commit 6fa2cc0

Browse files
authored
Update PhpStan and fix all issues (#61)
1 parent 1c2cb4a commit 6fa2cc0

File tree

13 files changed

+93
-33
lines changed

13 files changed

+93
-33
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"require-dev": {
2121
"phpunit/phpunit": "^9.5",
2222
"symfony/yaml": "^6.4|^7.4|^8.0",
23-
"phpstan/phpstan": "^1.7",
23+
"phpstan/phpstan": "^2.1",
2424
"symplify/easy-coding-standard": "^13.0"
2525
},
2626
"autoload": {

phpstan-baseline.neon

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Property Yokai\\\\SecurityTokenBundle\\\\Entity\\\\Token\\:\\:\\$id is never written, only read\\.$#"
4+
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\Token\:\:\$id \(int\|null\) is never assigned int so it can be removed from the property type\.$#'
5+
identifier: property.unusedType
56
count: 1
67
path: src/Entity/Token.php
78

89
-
9-
message: "#^Property Yokai\\\\SecurityTokenBundle\\\\Entity\\\\TokenUsage\\:\\:\\$id is never written, only read\\.$#"
10+
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\Token\:\:\$id is never written, only read\.$#'
11+
identifier: property.onlyRead
12+
count: 1
13+
path: src/Entity/Token.php
14+
15+
-
16+
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\TokenUsage\:\:\$id \(int\|null\) is never assigned int so it can be removed from the property type\.$#'
17+
identifier: property.unusedType
18+
count: 1
19+
path: src/Entity/TokenUsage.php
20+
21+
-
22+
message: '#^Property Yokai\\SecurityTokenBundle\\Entity\\TokenUsage\:\:\$id is never written, only read\.$#'
23+
identifier: property.onlyRead
1024
count: 1
1125
path: src/Entity/TokenUsage.php
1226

phpstan.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,5 @@ includes:
22
- phpstan-baseline.neon
33
parameters:
44
level: max
5-
ignoreErrors:
6-
- identifier: missingType.generics
7-
- identifier: missingType.iterableValue
85
paths:
96
- src/

src/Archive/DeleteArchivist.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use DateTime;
88
use Doctrine\ORM\EntityRepository;
9+
use Yokai\SecurityTokenBundle\Entity\Token;
910

1011
/**
1112
* This archivist is removing all outdated tokens based on the `keepUntil` property.
@@ -15,12 +16,12 @@
1516
final class DeleteArchivist implements ArchivistInterface
1617
{
1718
/**
18-
* @var EntityRepository
19+
* @var EntityRepository<Token>
1920
*/
2021
private $tokenRepository;
2122

2223
/**
23-
* @param EntityRepository $tokenRepository The token entity repository
24+
* @param EntityRepository<Token> $tokenRepository The token entity repository
2425
*/
2526
public function __construct(EntityRepository $tokenRepository)
2627
{

src/DependencyInjection/Configuration.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,37 @@
44

55
namespace Yokai\SecurityTokenBundle\DependencyInjection;
66

7-
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
7+
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
88
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
99
use Symfony\Component\Config\Definition\ConfigurationInterface;
1010

1111
/**
1212
* @author Yann Eugoné <[email protected]>
13+
*
14+
* @phpstan-type Config array{
15+
* tokens: array<
16+
* array{
17+
* generator: string,
18+
* duration: string,
19+
* usages: int,
20+
* keep: string,
21+
* unique: bool,
22+
* },
23+
* >,
24+
* services: array{
25+
* information_guesser: string,
26+
* token_factory: string,
27+
* token_repository: string,
28+
* token_manager: string,
29+
* archivist: string,
30+
* },
31+
* }
1332
*/
1433
final class Configuration implements ConfigurationInterface
1534
{
35+
/**
36+
* @return TreeBuilder<'array'>
37+
*/
1638
public function getConfigTreeBuilder(): TreeBuilder
1739
{
1840
$builder = new TreeBuilder('yokai_security_token');
@@ -29,7 +51,10 @@ public function getConfigTreeBuilder(): TreeBuilder
2951
return $builder;
3052
}
3153

32-
private function getTokensNode(): NodeDefinition
54+
/**
55+
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
56+
*/
57+
private function getTokensNode(): ArrayNodeDefinition
3358
{
3459
$builder = new TreeBuilder('tokens');
3560
$node = $builder->getRootNode();
@@ -60,7 +85,10 @@ private function getTokensNode(): NodeDefinition
6085
return $node;
6186
}
6287

63-
private function getServicesNode(): NodeDefinition
88+
/**
89+
* @return ArrayNodeDefinition<TreeBuilder<'array'>>
90+
*/
91+
private function getServicesNode(): ArrayNodeDefinition
6492
{
6593
$builder = new TreeBuilder('services');
6694
$node = $builder->getRootNode();

src/DependencyInjection/YokaiSecurityTokenExtension.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818

1919
/**
2020
* @author Yann Eugoné <[email protected]>
21+
*
22+
* @phpstan-import-type Config from Configuration
2123
*/
2224
final class YokaiSecurityTokenExtension extends Extension
2325
{
2426
public function load(array $configs, ContainerBuilder $container): void
2527
{
28+
/** @var Config $config */
2629
$config = $this->processConfiguration(new Configuration(), $configs);
2730

2831
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
@@ -33,6 +36,9 @@ public function load(array $configs, ContainerBuilder $container): void
3336
$this->registerAutoconfigureAliases($container);
3437
}
3538

39+
/**
40+
* @param Config $config
41+
*/
3642
private function registerTokens(array $config, ContainerBuilder $container): void
3743
{
3844
foreach ($config['tokens'] as $name => $token) {
@@ -48,10 +54,11 @@ private function registerTokens(array $config, ContainerBuilder $container): voi
4854
}
4955
}
5056

57+
/**
58+
* @param Config $config
59+
*/
5160
private function registerAliases(array $config, ContainerBuilder $container): void
5261
{
53-
$isTest = $container->getParameter('kernel.environment') === 'test';
54-
5562
foreach ($config['services'] as $name => $service) {
5663
$alias = $container->setAlias(\sprintf('yokai_security_token.%s', $name), $service);
5764
$alias->setPublic(true);

src/Entity/Token.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ public function getCreatedAt(): DateTime
144144
return $this->createdAt;
145145
}
146146

147+
/**
148+
* @return array<string, mixed>
149+
*/
147150
public function getCreatedInformation(): array
148151
{
149152
return $this->createdInformation;
@@ -198,6 +201,8 @@ public function getLastUsage(): TokenUsage|null
198201
}
199202

200203
/**
204+
* @param array<string, mixed> $information
205+
*
201206
* @throws LogicException
202207
*/
203208
public function consume(array $information, DateTime|null $date = null): void

src/Event/ConsumeTokenEvent.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ final class ConsumeTokenEvent extends Event
2626
private $at;
2727

2828
/**
29-
* @var array
29+
* @var array<string, mixed>
3030
*/
3131
private $information;
3232

3333
/**
34-
* @param Token $token The consumed token
35-
* @param DateTime|null $at Date/time at which the token has been consumed
36-
* @param array $information Some context information
34+
* @param Token $token The consumed token
35+
* @param DateTime|null $at Date/time at which the token has been consumed
36+
* @param array<string, mixed> $information Some context information
3737
*/
3838
public function __construct(Token $token, DateTime|null $at, array $information)
3939
{
@@ -60,6 +60,8 @@ public function getAt(): DateTime|null
6060

6161
/**
6262
* Some context information
63+
*
64+
* @return array<string, mixed>
6365
*/
6466
public function getInformation(): array
6567
{

src/Event/CreateTokenEvent.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ final class CreateTokenEvent extends Event
2424
private $user;
2525

2626
/**
27-
* @var array
27+
* @var array<string, mixed>
2828
*/
2929
private $payload;
3030

3131
/**
32-
* @param string $purpose The token purpose
33-
* @param mixed $user The associated user
34-
* @param array $payload The token payload
32+
* @param string $purpose The token purpose
33+
* @param mixed $user The associated user
34+
* @param array<string, mixed> $payload The token payload
3535
*/
3636
public function __construct(string $purpose, $user, array $payload)
3737
{
@@ -62,6 +62,8 @@ public function getUser()
6262

6363
/**
6464
* The token payload
65+
*
66+
* @return array<string, mixed>
6567
*/
6668
public function getPayload(): array
6769
{
@@ -71,7 +73,7 @@ public function getPayload(): array
7173
/**
7274
* Replace token payload
7375
*
74-
* @param array $payload The new payload value
76+
* @param array<string, mixed> $payload The new payload value
7577
*/
7678
public function setPayload(array $payload): void
7779
{
@@ -81,7 +83,7 @@ public function setPayload(array $payload): void
8183
/**
8284
* Add payload information to token
8385
*
84-
* @param array $payload Some payload to add
86+
* @param array<string, mixed> $payload Some payload to add
8587
*/
8688
public function addPayload(array $payload): void
8789
{

src/EventDispatcher.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public function __construct(EventDispatcherInterface $eventDispatcher)
3333
}
3434

3535
/**
36-
* @param mixed $user
36+
* @param mixed $user
37+
* @param array<string, mixed> $payload
3738
*/
3839
public function createToken(string $purpose, $user, array $payload): CreateTokenEvent
3940
{
@@ -53,6 +54,9 @@ public function tokenCreated(Token $token): TokenCreatedEvent
5354
return $event;
5455
}
5556

57+
/**
58+
* @param array<string, mixed> $information
59+
*/
5660
public function consumeToken(Token $token, DateTime|null $at = null, array $information = []): ConsumeTokenEvent
5761
{
5862
$this->eventDispatcher->dispatch(

0 commit comments

Comments
 (0)