Skip to content

Commit cee1e71

Browse files
committed
feature #223 Migrate from vimeo/psalm to phpstan/phpstan (ajgarlag)
This PR was squashed before being merged into the 1.x-dev branch. Discussion ---------- Migrate from vimeo/psalm to phpstan/phpstan Depends on #222 Commits ------- 1980f54 Migrate from vimeo/psalm to phpstan/phpstan
2 parents 74344b0 + 1980f54 commit cee1e71

39 files changed

+140
-307
lines changed

.github/workflows/static-analysis.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,25 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
doctrine-orm: ['2.14.*', '2.18.*', '3.0.*']
17+
php: ['8.4']
18+
symfony: ['7.2.*']
1819
composer-flags: ['--prefer-stable']
1920

21+
env:
22+
SYMFONY_REQUIRE: ${{ matrix.symfony }}
23+
2024
steps:
2125
- name: "checkout"
2226
uses: "actions/checkout@v4"
2327

2428
- name: "build the environment"
25-
run: "dev/bin/docker-compose build"
26-
27-
- name: "require specific Doctrine ORM version"
28-
run: "dev/bin/php composer require --ansi ${{ matrix.composer-flags }} doctrine/orm:${{ matrix.doctrine-orm }}"
29+
run: "dev/bin/docker-compose build --build-arg PHP_VERSION=${{ matrix.php }} php"
2930

3031
- name: "install dependencies"
3132
run: "dev/bin/php composer update --ansi ${{ matrix.composer-flags }}"
3233

33-
- name: "run static analysis"
34-
run: "dev/bin/php psalm --shepherd --stats"
34+
- name: "run phpstan static analysis"
35+
run: "dev/bin/php phpstan --memory-limit=256M --ansi"
3536

3637
- name: clear docker volumes
3738
if: ${{ always() }}

.psalm.baseline.xml

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

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.dist.neon

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

psalm.xml

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

src/Command/GenerateKeyPairCommand.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ final class GenerateKeyPairCommand extends Command
3131
'ES512',
3232
];
3333

34-
/**
35-
* @deprecated
36-
*/
37-
protected static $defaultName = 'league:oauth2-server:generate-keypair';
38-
3934
private Filesystem $filesystem;
4035

4136
private string $secretKey;
@@ -142,19 +137,19 @@ private function generateKeyPair(?string $passphrase, string $algorithm): array
142137

143138
$resource = openssl_pkey_new($config);
144139
if (false === $resource) {
145-
throw new \RuntimeException(openssl_error_string());
140+
throw new \RuntimeException(openssl_error_string() ?: '');
146141
}
147142

148143
$success = openssl_pkey_export($resource, $privateKey, $passphrase);
149144

150145
if (false === $success) {
151-
throw new \RuntimeException(openssl_error_string());
146+
throw new \RuntimeException(openssl_error_string() ?: '');
152147
}
153148

154149
$publicKeyData = openssl_pkey_get_details($resource);
155150

156151
if (!\is_array($publicKeyData)) {
157-
throw new \RuntimeException(openssl_error_string());
152+
throw new \RuntimeException(openssl_error_string() ?: '');
158153
}
159154

160155
if (!\array_key_exists('key', $publicKeyData) || !\is_string($publicKeyData['key'])) {
@@ -164,6 +159,9 @@ private function generateKeyPair(?string $passphrase, string $algorithm): array
164159
return [$privateKey, $publicKeyData['key']];
165160
}
166161

162+
/**
163+
* @return mixed[]
164+
*/
167165
private function buildOpenSSLConfiguration(string $algorithm): array
168166
{
169167
$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 array<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 array<ClientInterface> $clients
116+
* @param array<string> $columns
117+
*
118+
* @return array<array<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: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,19 @@ private function getClientActiveFromInput(InputInterface $input, bool $actual):
9494
}
9595

9696
/**
97-
* @template T1 of RedirectUri
98-
* @template T2 of Grant
99-
* @template T3 of Scope
97+
* @template T of RedirectUri|Grant|Scope
10098
*
101-
* @param class-string<T1>|class-string<T2>|class-string<T3> $modelFqcn
99+
* @param list<\Stringable> $actual
100+
* @param class-string<T> $modelFqcn
102101
*
103-
* @return list<T1>|list<T2>|list<T3>
104-
*
105-
* @psalm-suppress UnsafeInstantiation
102+
* @return list<T>
106103
*/
107104
private function getClientRelatedModelsFromInput(InputInterface $input, string $modelFqcn, array $actual, string $argument): array
108105
{
109-
/** @var list<string> $toAdd */
106+
/** @var list<non-empty-string> $toAdd */
110107
$toAdd = $input->getOption($addArgument = \sprintf('add-%s', $argument));
111108

112-
/** @var list<string> $toRemove */
109+
/** @var list<non-empty-string> $toRemove */
113110
$toRemove = $input->getOption($removeArgument = \sprintf('remove-%s', $argument));
114111

115112
if ([] !== $colliding = array_intersect($toAdd, $toRemove)) {
@@ -120,7 +117,7 @@ private function getClientRelatedModelsFromInput(InputInterface $input, string $
120117
return !\in_array((string) $model, $toRemove);
121118
});
122119

123-
/** @var list<T1>|list<T2>|list<T3> */
120+
/** @var list<T> */
124121
return array_merge($filtered, array_map(static function (string $value) use ($modelFqcn) {
125122
return new $modelFqcn($value);
126123
}, $toAdd));

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/Grant.php

Lines changed: 1 addition & 1 deletion
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<GrantModel>
2828
*/

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
{

src/DBAL/Type/RedirectUri.php

Lines changed: 1 addition & 1 deletion
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<RedirectUriModel>
2828
*/

0 commit comments

Comments
 (0)