Skip to content

Commit bdbb0f0

Browse files
committed
Upgrade to PHPStan v2
1 parent 5b9e1d8 commit bdbb0f0

9 files changed

Lines changed: 57 additions & 27 deletions

File tree

CONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing
2+
3+
This project is part of the Symfony ecosystem and follows the
4+
[Symfony Contribution Guidelines](https://symfony.com/doc/current/contributing/index.html).
5+
6+
## Running Tests
7+
8+
This project uses [PHPUnit Bridge](https://phpunit.de/getting-started/phpunit-bridge.html) to run the tests.
9+
10+
Install the required dependencies with:
11+
12+
```bash
13+
composer install
14+
```
15+
16+
To run the tests, use the following command:
17+
18+
```bash
19+
./vendor/bin/simple-phpunit
20+
```
21+
22+
## Static Analysis
23+
24+
This project uses [PHPStan](https://phpstan.org/) for static analysis.
25+
To run PHPStan, use the following command:
26+
27+
Install the required dependencies for the project, PHPStan itself and the extra
28+
packages that the project uses:
29+
30+
```bash
31+
composer update
32+
composer update --working-dir=tools/phpstan
33+
composer update --working-dir=tools/phpstan/includes
34+
```
35+
36+
Run PHPStan with:
37+
38+
```bash
39+
tools/phpstan/vendor/bin/phpstan
40+
```

src/Maker/MakeResetPassword.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function configureDependencies(DependencyBuilder $dependencies): void
139139

140140
// reset-password-bundle 1.6 includes the ability to generate a fake token.
141141
// we need to check that version 1.6 is installed
142+
// @phpstan-ignore function.alreadyNarrowedType
142143
if (class_exists(ResetPasswordHelper::class) && !method_exists(ResetPasswordHelper::class, 'generateFakeResetToken')) {
143144
throw new RuntimeCommandException('Please run "composer upgrade symfonycasts/reset-password-bundle". Version 1.6 or greater of this bundle is required.');
144145
}

src/Maker/MakeStimulusController.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Symfony\Component\Console\Input\InputOption;
2323
use Symfony\Component\Console\Question\Question;
2424
use Symfony\UX\StimulusBundle\StimulusBundle;
25-
use Symfony\WebpackEncoreBundle\WebpackEncoreBundle;
2625

2726
/**
2827
* @author Abdelilah Jabri <jbrabdelilah@gmail.com>
@@ -339,17 +338,7 @@ private function generateUsageExample(string $name, array $targets, array $value
339338

340339
public function configureDependencies(DependencyBuilder $dependencies): void
341340
{
342-
// lower than 8.1, allow WebpackEncoreBundle
343-
if (\PHP_VERSION_ID < 80100) {
344-
$dependencies->addClassDependency(
345-
WebpackEncoreBundle::class,
346-
'symfony/webpack-encore-bundle'
347-
);
348-
349-
return;
350-
}
351-
352-
// else: encourage StimulusBundle by requiring it
341+
// Encourage StimulusBundle by requiring it
353342
$dependencies->addClassDependency(
354343
StimulusBundle::class,
355344
'symfony/stimulus-bundle'

src/Maker/MakeUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
221221
} else {
222222
$nextSteps[] = \sprintf(
223223
'Open <info>%s</info> to finish implementing your user provider.',
224-
/* @phpstan-ignore-next-line - $customProviderPath is defined in this else statement */
224+
// @phpstan-ignore variable.undefined ($customProviderPath is defined in this else statement)
225225
$this->fileManager->relativizePath($customProviderPath)
226226
);
227227
}

tests/Command/MakerCommandTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MakerCommandTest extends TestCase
2626
public function testExceptionOnMissingDependencies(): void
2727
{
2828
$this->expectException(RuntimeCommandException::class);
29+
// @phpstan-ignore function.alreadyNarrowedType
2930
if (method_exists($this, 'expectExceptionMessageMatches')) {
3031
$this->expectExceptionMessageMatches('/composer require foo-package/');
3132
}

tests/Maker/MakeControllerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public function getTestDetails(): \Generator
4141

4242
// Ensure the generated controller matches what we expect
4343
self::assertSame(
44-
expected: file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalController.php'),
45-
actual: file_get_contents($runner->getPath('src/Controller/FooBarController.php'))
44+
file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalController.php'),
45+
file_get_contents($runner->getPath('src/Controller/FooBarController.php'))
4646
);
4747
}),
4848
];
@@ -92,8 +92,8 @@ public function getTestDetails(): \Generator
9292

9393
// Ensure the generated controller matches what we expect
9494
self::assertSame(
95-
expected: file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalControllerWithTemplate.php'),
96-
actual: file_get_contents($runner->getPath('src/Controller/FooTwigController.php'))
95+
file_get_contents(\dirname(__DIR__).'/fixtures/make-controller/expected/FinalControllerWithTemplate.php'),
96+
file_get_contents($runner->getPath('src/Controller/FooTwigController.php'))
9797
);
9898
}),
9999
];

tests/Maker/MakeSerializerEncoderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function getTestDetails(): \Generator
3939
);
4040

4141
self::assertStringContainsString(
42-
needle: 'public function decode(string $data, string $format, array $context = []): mixed',
43-
haystack: file_get_contents($runner->getPath('src/Serializer/FooBarEncoder.php'))
42+
'public function decode(string $data, string $format, array $context = []): mixed',
43+
file_get_contents($runner->getPath('src/Serializer/FooBarEncoder.php'))
4444
);
4545
}),
4646
];
@@ -61,8 +61,8 @@ public function getTestDetails(): \Generator
6161
);
6262

6363
self::assertStringNotContainsString(
64-
needle: 'public function decode(string $data, string $format, array $context = []): mixed',
65-
haystack: file_get_contents($runner->getPath('src/Serializer/FooBarEncoder.php'))
64+
'public function decode(string $data, string $format, array $context = []): mixed',
65+
file_get_contents($runner->getPath('src/Serializer/FooBarEncoder.php'))
6666
);
6767
}),
6868
];

tools/phpstan/composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"require": {
3-
"phpstan/phpstan": "^1.10",
4-
"phpstan/extension-installer": "^1.3",
5-
"phpstan/phpstan-symfony": "^1.3",
6-
"phpstan/phpstan-doctrine": "^1.3",
7-
"phpstan/phpstan-phpunit": "^1.3"
3+
"phpstan/phpstan": "^2.1",
4+
"phpstan/extension-installer": "^1.4",
5+
"phpstan/phpstan-symfony": "^2",
6+
"phpstan/phpstan-doctrine": "^2",
7+
"phpstan/phpstan-phpunit": "^2"
88
},
99
"config": {
1010
"allow-plugins": {

tools/phpstan/includes/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"symfony/validator": "^7.0",
1717
"symfonycasts/reset-password-bundle": "^1.21",
1818
"symfonycasts/verify-email-bundle": "^1.17",
19-
"symfony/webpack-encore-bundle": "^2.1",
2019
"symfony/panther": "^2.1",
2120
"symfony/webhook": "^7.0",
2221
"symfony/expression-language": "^7.0"

0 commit comments

Comments
 (0)