Skip to content

Commit d343b9a

Browse files
committed
Fix psalm
1 parent c2f5c0e commit d343b9a

12 files changed

+36
-22
lines changed

src/Command/CreateClientCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ private function buildClientFromInput(InputInterface $input): ClientInterface
135135
$client->setActive(true);
136136
$client->setAllowPlainTextPkce($input->getOption('allow-plain-text-pkce'));
137137

138-
/** @var list<string> $redirectUriStrings */
138+
/** @var list<non-empty-string> $redirectUriStrings */
139139
$redirectUriStrings = $input->getOption('redirect-uri');
140-
/** @var list<string> $grantStrings */
140+
/** @var list<non-empty-string> $grantStrings */
141141
$grantStrings = $input->getOption('grant-type');
142-
/** @var list<string> $scopeStrings */
142+
/** @var list<non-empty-string> $scopeStrings */
143143
$scopeStrings = $input->getOption('scope');
144144

145145
return $client

src/Command/ListClientsCommand.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8080

8181
private function getFindByCriteria(InputInterface $input): ClientFilter
8282
{
83-
/** @var list<string> $grantStrings */
83+
/** @var list<non-empty-string> $grantStrings */
8484
$grantStrings = $input->getOption('grant-type');
85-
/** @var list<string> $redirectUriStrings */
85+
/** @var list<non-empty-string> $redirectUriStrings */
8686
$redirectUriStrings = $input->getOption('redirect-uri');
87-
/** @var list<string> $scopeStrings */
87+
/** @var list<non-empty-string> $scopeStrings */
8888
$scopeStrings = $input->getOption('scope');
8989

9090
return ClientFilter::create()

src/Converter/UserConverter.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public function toLeague(?UserInterface $user): UserEntityInterface
1818
{
1919
$userEntity = new User();
2020
if ($user instanceof UserInterface) {
21-
$userEntity->setIdentifier(method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername());
21+
$identifier = method_exists($user, 'getUserIdentifier') ? $user->getUserIdentifier() : $user->getUsername();
22+
if ('' === $identifier) {
23+
throw new \RuntimeException('Emtpy identifier not allowed');
24+
}
25+
$userEntity->setIdentifier($identifier);
2226
}
2327

2428
return $userEntity;

src/DBAL/Type/ImplodedArray.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): arr
4949

5050
\assert(\is_string($value), 'Expected $value of be either a string or null.');
5151

52+
/** @var list<non-empty-string> $values */
5253
$values = explode(self::VALUE_DELIMITER, $value);
5354

5455
return $this->convertDatabaseValues($values);
@@ -87,7 +88,7 @@ private function assertValueCanBeImploded($value): void
8788
}
8889

8990
/**
90-
* @param list<string> $values
91+
* @param list<non-empty-string> $values
9192
*
9293
* @return list<T>
9394
*/

src/DBAL/Type/Scope.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function getName(): string
2222
}
2323

2424
/**
25-
* @param list<string> $values
25+
* @param list<non-empty-string> $values
2626
*
2727
* @return list<ScopeModel>
2828
*/

src/EventListener/AddClientDefaultScopesListener.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
class AddClientDefaultScopesListener
1616
{
1717
/**
18-
* @var list<string>
18+
* @var list<non-empty-string>
1919
*/
2020
private $defaultScopes;
2121

2222
/**
23-
* @param list<string> $defaultScopes
23+
* @param list<non-empty-string> $defaultScopes
2424
*/
2525
public function __construct(array $defaultScopes)
2626
{

src/Model/AbstractClient.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
abstract class AbstractClient implements ClientInterface
1717
{
1818
private string $name;
19+
/** @var non-empty-string */
1920
protected string $identifier;
2021
private ?string $secret;
2122

@@ -33,6 +34,8 @@ abstract class AbstractClient implements ClientInterface
3334

3435
/**
3536
* @psalm-mutation-free
37+
*
38+
* @param non-empty-string $identifier
3639
*/
3740
public function __construct(string $name, string $identifier, ?string $secret)
3841
{

src/Model/ClientInterface.php

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
*/
1414
interface ClientInterface
1515
{
16+
/**
17+
* @return non-empty-string
18+
*/
1619
public function getIdentifier(): string;
1720

1821
public function getSecret(): ?string;

src/Repository/AccessTokenRepository.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ public function __construct(
4242
$this->scopeConverter = $scopeConverter;
4343
}
4444

45-
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, mixed $userIdentifier = null): AccessTokenEntityInterface
45+
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, ?string $userIdentifier = null): AccessTokenEntityInterface
4646
{
47-
/** @var int|string|null $userIdentifier */
4847
$accessToken = new AccessTokenEntity();
4948
$accessToken->setClient($clientEntity);
50-
$accessToken->setUserIdentifier($userIdentifier);
49+
if (null !== $userIdentifier && '' !== $userIdentifier) {
50+
$accessToken->setUserIdentifier($userIdentifier);
51+
}
5152

5253
foreach ($scopes as $scope) {
5354
$accessToken->addScope($scope);
@@ -99,9 +100,6 @@ private function buildAccessTokenModel(AccessTokenEntityInterface $accessTokenEn
99100
$client = $this->clientManager->find($accessTokenEntity->getClient()->getIdentifier());
100101

101102
$userIdentifier = $accessTokenEntity->getUserIdentifier();
102-
if (null !== $userIdentifier) {
103-
$userIdentifier = (string) $userIdentifier;
104-
}
105103

106104
return new AccessTokenModel(
107105
$accessTokenEntity->getIdentifier(),

src/Repository/AuthCodeRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function buildAuthorizationCode(AuthCodeEntityInterface $authCodeEntity)
9090

9191
$userIdentifier = $authCodeEntity->getUserIdentifier();
9292
if (null !== $userIdentifier) {
93-
$userIdentifier = (string) $userIdentifier;
93+
$userIdentifier = $userIdentifier;
9494
}
9595

9696
return new AuthorizationCode(

src/Repository/NullAccessTokenRepository.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111

1212
final class NullAccessTokenRepository implements AccessTokenRepositoryInterface
1313
{
14-
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, mixed $userIdentifier = null): AccessTokenEntityInterface
14+
public function getNewToken(ClientEntityInterface $clientEntity, array $scopes, ?string $userIdentifier = null): AccessTokenEntityInterface
1515
{
16-
/** @var int|string|null $userIdentifier */
1716
$accessToken = new AccessTokenEntity();
1817
$accessToken->setClient($clientEntity);
19-
$accessToken->setUserIdentifier($userIdentifier);
18+
if (null !== $userIdentifier && '' !== $userIdentifier) {
19+
$accessToken->setUserIdentifier($userIdentifier);
20+
}
2021

2122
foreach ($scopes as $scope) {
2223
$accessToken->addScope($scope);

src/ValueObject/Scope.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
class Scope
1111
{
1212
/**
13-
* @var string
13+
* @var non-empty-string
1414
*/
1515
private $scope;
1616

1717
/**
1818
* @psalm-mutation-free
19+
*
20+
* @param non-empty-string $scope
1921
*/
2022
public function __construct(string $scope)
2123
{
@@ -24,6 +26,8 @@ public function __construct(string $scope)
2426

2527
/**
2628
* @psalm-mutation-free
29+
*
30+
* @return non-empty-string
2731
*/
2832
public function __toString(): string
2933
{

0 commit comments

Comments
 (0)