Skip to content

Commit c117131

Browse files
committed
Migrate from vimeo/psalm to phpstan/phpstan
1 parent 3d53fd7 commit c117131

34 files changed

+190
-261
lines changed

.github/workflows/static-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ jobs:
3030
- name: "install dependencies"
3131
run: "dev/bin/php composer update --ansi ${{ matrix.composer-flags }}"
3232

33-
- name: "run static analysis"
34-
run: "dev/bin/php psalm --shepherd --stats"
33+
- name: "run phpstan static analysis"
34+
run: "dev/bin/php phpstan --ansi"
3535

3636
- name: clear docker volumes
3737
if: ${{ always() }}

dev/docker/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ RUN su-exec app composer global config --no-interaction allow-plugins.bamarni/co
5959
RUN su-exec app composer global bin php-cs-fixer require --dev friendsofphp/php-cs-fixer \
6060
&& ln -s /home/app/.composer/vendor/bin/php-cs-fixer /app/bin/php-cs-fixer
6161

62-
# Psalm
63-
RUN su-exec app composer global bin psalm require --dev vimeo/psalm psalm/plugin-symfony \
64-
&& ln -s /home/app/.composer/vendor/bin/psalm /app/bin/psalm
62+
# PHPstan
63+
RUN su-exec app composer global bin phpstan require --dev phpstan/phpstan phpstan/phpstan-symfony \
64+
&& ln -s /home/app/.composer/vendor/bin/phpstan /app/bin/phpstan
6565

6666
# Enable parallel package installation for Composer
6767
RUN su-exec app composer global require symfony/flex

phpstan-baseline.neon

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: '#^Parameter \#1 \$message of class RuntimeException constructor expects string, string\|false given\.$#'
5+
identifier: argument.type
6+
count: 3
7+
path: src/Command/GenerateKeyPairCommand.php
8+
9+
-
10+
message: '#^Parameter \#2 \$columns of method League\\Bundle\\OAuth2ServerBundle\\Command\\ListClientsCommand\:\:getRows\(\) expects list\<string\>, array\<string\> given\.$#'
11+
identifier: argument.type
12+
count: 1
13+
path: src/Command/ListClientsCommand.php
14+
15+
-
16+
message: '#^Parameter \#1 \$scope of class League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Scope constructor expects non\-empty\-string, string given\.$#'
17+
identifier: argument.type
18+
count: 1
19+
path: src/Command/UpdateClientCommand.php
20+
21+
-
22+
message: '#^Parameter \#1 \.\.\.\$grants of method League\\Bundle\\OAuth2ServerBundle\\Model\\ClientInterface\:\:setGrants\(\) expects League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Grant, League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Grant\|League\\Bundle\\OAuth2ServerBundle\\ValueObject\\RedirectUri\|League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Scope given\.$#'
23+
identifier: argument.type
24+
count: 1
25+
path: src/Command/UpdateClientCommand.php
26+
27+
-
28+
message: '#^Parameter \#1 \.\.\.\$redirectUris of method League\\Bundle\\OAuth2ServerBundle\\Model\\ClientInterface\:\:setRedirectUris\(\) expects League\\Bundle\\OAuth2ServerBundle\\ValueObject\\RedirectUri, League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Grant\|League\\Bundle\\OAuth2ServerBundle\\ValueObject\\RedirectUri\|League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Scope given\.$#'
29+
identifier: argument.type
30+
count: 1
31+
path: src/Command/UpdateClientCommand.php
32+
33+
-
34+
message: '#^Parameter \#1 \.\.\.\$scopes of method League\\Bundle\\OAuth2ServerBundle\\Model\\ClientInterface\:\:setScopes\(\) expects League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Scope, League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Grant\|League\\Bundle\\OAuth2ServerBundle\\ValueObject\\RedirectUri\|League\\Bundle\\OAuth2ServerBundle\\ValueObject\\Scope given\.$#'
35+
identifier: argument.type
36+
count: 1
37+
path: src/Command/UpdateClientCommand.php
38+
39+
-
40+
message: '#^Unable to resolve the template type T1 in call to method League\\Bundle\\OAuth2ServerBundle\\Command\\UpdateClientCommand\:\:getClientRelatedModelsFromInput\(\)$#'
41+
identifier: argument.templateType
42+
count: 2
43+
path: src/Command/UpdateClientCommand.php
44+
45+
-
46+
message: '#^Unable to resolve the template type T2 in call to method League\\Bundle\\OAuth2ServerBundle\\Command\\UpdateClientCommand\:\:getClientRelatedModelsFromInput\(\)$#'
47+
identifier: argument.templateType
48+
count: 2
49+
path: src/Command/UpdateClientCommand.php
50+
51+
-
52+
message: '#^Unable to resolve the template type T3 in call to method League\\Bundle\\OAuth2ServerBundle\\Command\\UpdateClientCommand\:\:getClientRelatedModelsFromInput\(\)$#'
53+
identifier: argument.templateType
54+
count: 2
55+
path: src/Command/UpdateClientCommand.php
56+
57+
-
58+
message: '#^Cannot call method getScopes\(\) on League\\Bundle\\OAuth2ServerBundle\\Security\\Passport\\Badge\\ScopeBadge\|null\.$#'
59+
identifier: method.nonObject
60+
count: 1
61+
path: src/Security/EventListener/CheckScopeListener.php
62+
63+
-
64+
message: '#^Cannot call method isResolved\(\) on League\\Bundle\\OAuth2ServerBundle\\Security\\Passport\\Badge\\ScopeBadge\|null\.$#'
65+
identifier: method.nonObject
66+
count: 1
67+
path: src/Security/EventListener/CheckScopeListener.php
68+
69+
-
70+
message: '#^Cannot call method markResolved\(\) on League\\Bundle\\OAuth2ServerBundle\\Security\\Passport\\Badge\\ScopeBadge\|null\.$#'
71+
identifier: method.nonObject
72+
count: 1
73+
path: src/Security/EventListener/CheckScopeListener.php
74+
75+
-
76+
message: '#^Method League\\Bundle\\OAuth2ServerBundle\\Security\\User\\ClientCredentialsUser\:\:getUserIdentifier\(\) should return non\-empty\-string but returns string\.$#'
77+
identifier: return.type
78+
count: 1
79+
path: src/Security/User/ClientCredentialsUser.php

phpstan.dist.neon

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
- /home/app/.composer/vendor-bin/phpstan/vendor/phpstan/phpstan-symfony/extension.neon
4+
- /home/app/.composer/vendor-bin/phpstan/vendor/phpstan/phpstan-symfony/rules.neon
5+
6+
parameters:
7+
level: 8
8+
paths:
9+
- src/
10+
scanFiles:
11+
- vendor/symfony/dependency-injection/Loader/Configurator/ContainerConfigurator.php
12+
treatPhpDocTypesAsCertain: false

psalm.xml

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/Command/GenerateKeyPairCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ private function generateKeyPair(?string $passphrase, string $algorithm): array
159159
return [$privateKey, $publicKeyData['key']];
160160
}
161161

162+
/**
163+
* @return mixed[]
164+
*/
162165
private function buildOpenSSLConfiguration(string $algorithm): array
163166
{
164167
$digestAlgorithms = [

src/Command/ListClientsCommand.php

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

77
use League\Bundle\OAuth2ServerBundle\Manager\ClientFilter;
88
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
9-
use League\Bundle\OAuth2ServerBundle\Model\AbstractClient;
9+
use League\Bundle\OAuth2ServerBundle\Model\ClientInterface;
1010
use League\Bundle\OAuth2ServerBundle\ValueObject\Grant;
1111
use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri;
1212
use League\Bundle\OAuth2ServerBundle\ValueObject\Scope;
@@ -100,6 +100,9 @@ private function getFindByCriteria(InputInterface $input): ClientFilter
100100
;
101101
}
102102

103+
/**
104+
* @param list<ClientInterface> $clients
105+
*/
103106
private function drawTable(InputInterface $input, OutputInterface $output, array $clients): void
104107
{
105108
$io = new SymfonyStyle($input, $output);
@@ -108,9 +111,15 @@ private function drawTable(InputInterface $input, OutputInterface $output, array
108111
$io->table($columns, $rows);
109112
}
110113

114+
/**
115+
* @param list<ClientInterface> $clients
116+
* @param list<string> $columns
117+
*
118+
* @return list<list<string>>
119+
*/
111120
private function getRows(array $clients, array $columns): array
112121
{
113-
return array_map(static function (AbstractClient $client) use ($columns): array {
122+
return array_map(static function (ClientInterface $client) use ($columns): array {
114123
$values = [
115124
'name' => $client->getName(),
116125
'identifier' => $client->getIdentifier(),
@@ -126,6 +135,9 @@ private function getRows(array $clients, array $columns): array
126135
}, $clients);
127136
}
128137

138+
/**
139+
* @return array<string>
140+
*/
129141
private function getColumns(InputInterface $input): array
130142
{
131143
$requestedColumns = $input->getOption('columns');

src/Command/UpdateClientCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ private function getClientActiveFromInput(InputInterface $input, bool $actual):
9898
* @template T2 of Grant
9999
* @template T3 of Scope
100100
*
101+
* @param list<\Stringable> $actual
101102
* @param class-string<T1>|class-string<T2>|class-string<T3> $modelFqcn
102103
*
103104
* @return list<T1>|list<T2>|list<T3>
104-
*
105-
* @psalm-suppress UnsafeInstantiation
106105
*/
107106
private function getClientRelatedModelsFromInput(InputInterface $input, string $modelFqcn, array $actual, string $argument): array
108107
{

src/Converter/UserConverter.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010

1111
final class UserConverter implements UserConverterInterface
1212
{
13-
/**
14-
* @psalm-suppress ArgumentTypeCoercion
15-
* @psalm-suppress UndefinedInterfaceMethod
16-
*/
1713
public function toLeague(UserInterface $user): UserEntityInterface
1814
{
1915
$userEntity = new User();

src/DBAL/Type/ImplodedArray.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Doctrine\DBAL\Types\TextType;
99

1010
/**
11-
* @psalm-template T
11+
* @template T
1212
*/
1313
abstract class ImplodedArray extends TextType
1414
{
@@ -17,9 +17,6 @@ abstract class ImplodedArray extends TextType
1717
*/
1818
private const VALUE_DELIMITER = ' ';
1919

20-
/**
21-
* @psalm-suppress MixedArgumentTypeCoercion
22-
*/
2320
public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): ?string
2421
{
2522
if (!\is_array($value)) {
@@ -30,7 +27,6 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)
3027
return null;
3128
}
3229

33-
/** @psalm-var T $item */
3430
foreach ($value as $item) {
3531
$this->assertValueCanBeImploded($item);
3632
}
@@ -39,7 +35,7 @@ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform)
3935
}
4036

4137
/**
42-
* @psalm-return list<T>
38+
* @return list<T>
4339
*/
4440
public function convertToPHPValue(mixed $value, AbstractPlatform $platform): array
4541
{
@@ -68,7 +64,7 @@ public function requiresSQLCommentHint(AbstractPlatform $platform): bool
6864
}
6965

7066
/**
71-
* @psalm-param T $value
67+
* @param T $value
7268
*/
7369
private function assertValueCanBeImploded($value): void
7470
{

0 commit comments

Comments
 (0)