Skip to content

Commit 1cbd4b2

Browse files
committed
Fixed PhpStan issues
1 parent 4b84f7b commit 1cbd4b2

File tree

11 files changed

+31
-61
lines changed

11 files changed

+31
-61
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:addDefaultsIfNotSet\\(\\)\\.$#"
5-
count: 2
6-
path: src/DependencyInjection/Configuration.php
7-
8-
-
9-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:children\\(\\)\\.$#"
10-
count: 2
11-
path: src/DependencyInjection/Configuration.php
12-
13-
-
14-
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\NodeDefinition\\:\\:useAttributeAsKey\\(\\)\\.$#"
15-
count: 1
16-
path: src/DependencyInjection/Configuration.php
17-
18-
-
19-
message: "#^Method Yokai\\\\SecurityTokenBundle\\\\Entity\\\\Token\\:\\:getLastUsage\\(\\) should return Yokai\\\\SecurityTokenBundle\\\\Entity\\\\TokenUsage\\|null but returns mixed\\.$#"
20-
count: 1
21-
path: src/Entity/Token.php
22-
23-
-
24-
message: "#^Method Yokai\\\\SecurityTokenBundle\\\\Entity\\\\Token\\:\\:getUsages\\(\\) should return array\\<Yokai\\\\SecurityTokenBundle\\\\Entity\\\\TokenUsage\\> but returns array\\.$#"
25-
count: 1
26-
path: src/Entity/Token.php
27-
283
-
294
message: "#^Property Yokai\\\\SecurityTokenBundle\\\\Entity\\\\Token\\:\\:\\$id is never written, only read\\.$#"
305
count: 1
@@ -35,18 +10,3 @@ parameters:
3510
count: 1
3611
path: src/Entity/TokenUsage.php
3712

38-
-
39-
message: "#^Cannot cast mixed to string\\.$#"
40-
count: 1
41-
path: src/Manager/ChainUserManager.php
42-
43-
-
44-
message: "#^Cannot cast mixed to string\\.$#"
45-
count: 1
46-
path: src/Manager/DoctrineUserManager.php
47-
48-
-
49-
message: "#^Method Doctrine\\\\ORM\\\\EntityManager\\:\\:flush\\(\\) invoked with 1 parameter, 0 required\\.$#"
50-
count: 1
51-
path: src/Repository/DoctrineORMTokenRepository.php
52-

src/Archive/ArchivistInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ interface ArchivistInterface
1818
*
1919
* @return integer
2020
*/
21-
public function archive(string $purpose = null): int;
21+
public function archive(string|null $purpose = null): int;
2222
}

src/Archive/DeleteArchivist.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(EntityRepository $tokenRepository)
2727
$this->tokenRepository = $tokenRepository;
2828
}
2929

30-
public function archive(string $purpose = null): int
30+
public function archive(string|null $purpose = null): int
3131
{
3232
$builder = $this->tokenRepository->createQueryBuilder('token')
3333
->delete($this->tokenRepository->getClassName(), 'token');

src/Entity/Token.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class Token
7070
private $keepUntil;
7171

7272
/**
73-
* @var Collection<TokenUsage>
73+
* @var Collection<int, TokenUsage>
7474
*/
7575
private $usages;
7676

@@ -192,15 +192,15 @@ public function getUsages(): array
192192
return $this->usages->toArray();
193193
}
194194

195-
public function getLastUsage(): ?TokenUsage
195+
public function getLastUsage(): TokenUsage|null
196196
{
197-
return $this->usages->last();
197+
return $this->usages->last() ?: null;
198198
}
199199

200200
/**
201201
* @throws LogicException
202202
*/
203-
public function consume(array $information, DateTime $date = null): void
203+
public function consume(array $information, DateTime|null $date = null): void
204204
{
205205
if ($this->isConsumed()) {
206206
throw new LogicException(

src/Entity/TokenUsage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TokenUsage
3131
/**
3232
* @param array<string, mixed> $information
3333
*/
34-
public function __construct(Token $token, array $information, DateTime $createdAt = null)
34+
public function __construct(Token $token, array $information, DateTime|null $createdAt = null)
3535
{
3636
$this->token = $token;
3737
$this->information = $information;

src/EventDispatcher.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function tokenCreated(Token $token): TokenCreatedEvent
5353
return $event;
5454
}
5555

56-
public function consumeToken(Token $token, DateTime $at = null, array $information = []): ConsumeTokenEvent
56+
public function consumeToken(Token $token, DateTime|null $at = null, array $information = []): ConsumeTokenEvent
5757
{
5858
$this->eventDispatcher->dispatch(
5959
$event = new ConsumeTokenEvent($token, $at, $information)
@@ -71,7 +71,6 @@ public function tokenConsumed(Token $token): TokenConsumedEvent
7171
return $event;
7272
}
7373

74-
7574
public function tokenTotallyConsumed(Token $token): TokenTotallyConsumedEvent
7675
{
7776
$this->eventDispatcher->dispatch(

src/Manager/ChainUserManager.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,18 @@ private function getManagerForUser($user): UserManagerInterface
108108
$tries[] = get_class($manager);
109109
}
110110

111-
if (is_object($user) && !method_exists($user, '__toString')) {
112-
$userAsString = sprintf('%s::%s', get_class($user), spl_object_hash($user));
111+
if (is_object($user)) {
112+
if (!method_exists($user, '__toString')) {
113+
$userAsString = sprintf('%s::%s', get_class($user), spl_object_hash($user));
114+
} else {
115+
$userAsString = (string)$user;
116+
}
113117
} else {
114-
$userAsString = (string)$user;
118+
if (is_scalar($user)) {
119+
$userAsString = (string)$user;
120+
} else {
121+
$userAsString = get_debug_type($user);
122+
}
115123
}
116124

117125
throw new \InvalidArgumentException(

src/Manager/DoctrineUserManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,15 @@ public function getId($user): string
6969
throw new \InvalidArgumentException('Entities with composite ids are not supported');
7070
}
7171

72-
return (string) reset($identifiers);
72+
$identifier = reset($identifiers);
73+
if (is_scalar($identifier)
74+
|| $identifier === null
75+
|| (is_object($identifier) && method_exists($identifier, '__toString'))
76+
) {
77+
return (string)$identifier;
78+
}
79+
80+
throw new \InvalidArgumentException('Entities with non stringable ids are not supported');
7381
}
7482

7583
/**

src/Manager/TokenManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function create(string $purpose, $user, array $payload = []): Token
101101
return $token;
102102
}
103103

104-
public function consume(Token $token, DateTime $at = null): void
104+
public function consume(Token $token, DateTime|null $at = null): void
105105
{
106106
$event = $this->eventDispatcher->consumeToken($token, $at, $this->informationGuesser->get());
107107

src/Manager/TokenManagerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function create(string $purpose, $user, array $payload = []): Token;
4848
* @param Token $token The token to consume
4949
* @param DateTime|null $at The date/time at which the token was consumed (defaults to now)
5050
*/
51-
public function consume(Token $token, DateTime $at = null): void;
51+
public function consume(Token $token, DateTime|null $at = null): void;
5252

5353
/**
5454
* Get the user associated to a token.

0 commit comments

Comments
 (0)