Skip to content

Commit 30cdf17

Browse files
authored
minor #1498 [ci] implement phpstan for static analysis of the codebase
1 parent f7ee250 commit 30cdf17

18 files changed

+161
-56
lines changed

.github/workflows/ci-linux.yaml

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,6 @@ env:
1313
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"
1414

1515
jobs:
16-
coding-standards:
17-
name: "Coding Standards (${{ matrix.php-version }})"
18-
19-
runs-on: ubuntu-latest
20-
21-
strategy:
22-
fail-fast: false
23-
matrix:
24-
php-version:
25-
- '8.1'
26-
27-
steps:
28-
-
29-
name: Checkout code
30-
uses: "actions/checkout@v3"
31-
32-
-
33-
name: Install PHP
34-
uses: "shivammathur/setup-php@v2"
35-
with:
36-
coverage: "none"
37-
php-version: "${{ matrix.php-version }}"
38-
39-
-
40-
name: Validate composer.json
41-
run: "composer validate --strict --no-check-lock"
42-
43-
-
44-
name: Composer install
45-
uses: "ramsey/composer-install@v2"
46-
with:
47-
composer-options: "--no-scripts"
48-
49-
-
50-
name: Composer install php-cs-fixer
51-
uses: "ramsey/composer-install@v2"
52-
with:
53-
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"
54-
55-
-
56-
name: Run PHP-CS-Fixer
57-
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"
58-
5916
test:
6017
name: "PHP ${{ matrix.php-version }} + @${{ matrix.symfony-version }} ${{ matrix.dependency-versions }} deps"
6118

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: "CI Static Analysis"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- 'main'
8+
schedule:
9+
- cron: '0 0 * * *'
10+
11+
env:
12+
PHPUNIT_FLAGS: "-v"
13+
SYMFONY_PHPUNIT_DIR: "$HOME/symfony-bridge/.phpunit"
14+
15+
jobs:
16+
coding-standards:
17+
name: "Coding Standards"
18+
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
-
23+
name: Checkout code
24+
uses: "actions/checkout@v3"
25+
26+
-
27+
name: Install PHP
28+
uses: "shivammathur/setup-php@v2"
29+
30+
-
31+
name: Validate composer.json
32+
run: "composer validate --strict --no-check-lock"
33+
34+
-
35+
name: Composer install
36+
uses: "ramsey/composer-install@v2"
37+
with:
38+
composer-options: "--no-scripts"
39+
40+
-
41+
name: Composer install php-cs-fixer
42+
uses: "ramsey/composer-install@v2"
43+
with:
44+
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"
45+
46+
-
47+
name: Run PHP-CS-Fixer
48+
run: "tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff"
49+
50+
phpstan:
51+
name: PHPStan
52+
53+
runs-on: ubuntu-latest
54+
55+
steps:
56+
- name: Checkout
57+
uses: "actions/checkout@v4"
58+
59+
- name: Install PHP
60+
uses: "shivammathur/setup-php@v2"
61+
62+
- name: Install Composer Dependencies
63+
uses: "ramsey/composer-install@v2"
64+
with:
65+
composer-options: "--no-scripts"
66+
67+
- name: Install PHPStan
68+
uses: "ramsey/composer-install@v2"
69+
with:
70+
composer-options: "--no-scripts --working-dir=tools/phpstan"
71+
72+
- name: Install Optional Dependencies
73+
uses: "ramsey/composer-install@v2"
74+
with:
75+
composer-options: "--no-scripts --working-dir=tools/phpstan/includes"
76+
77+
- name: Install PHPUnit
78+
run: "vendor/bin/simple-phpunit --version"
79+
80+
- name: Run PHPStan
81+
run: "tools/phpstan/vendor/bin/phpstan analyze --memory-limit=1G --error-format=github"

phpstan.dist.neon

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
parameters:
2+
level: 6
3+
bootstrapFiles:
4+
- vendor/autoload.php
5+
- tools/phpstan/includes/vendor/autoload.php
6+
paths:
7+
- src/Maker
8+
- tests/Command
9+
- tests/Docker
10+
- tests/Maker
11+
excludePaths:
12+
- tests/Doctrine/fixtures
13+
- tests/fixtures
14+
- tests/Security/fixtures
15+
- tests/Security/yaml_fixtures
16+
- tests/tmp
17+
- tests/Util/fixtures
18+
- tests/Util/yaml_fixtures
19+
ignoreErrors:
20+
-
21+
message: '#Property .+phpCompatUtil is never read, only written\.#'
22+
path: src/Maker/*
23+
24+
-
25+
message: '#Class Symfony\\Bundle\\MakerBundle\\Maker\\LegacyApiTestCase not found#'
26+
path: src/Maker/*

src/Maker/MakeEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
306306
}
307307

308308
foreach ($fileManagerOperations as $path => $manipulatorOrMessage) {
309-
if (\is_string($manipulatorOrMessage)) {
309+
if (\is_string($manipulatorOrMessage)) { /* @phpstan-ignore-line - https://github.com/symfony/maker-bundle/issues/1509 */
310310
$io->comment($manipulatorOrMessage);
311311
} else {
312312
$this->fileManager->dumpFile($path, $manipulatorOrMessage->getSourceCode());

src/Maker/MakeUser.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
220220
} else {
221221
$nextSteps[] = sprintf(
222222
'Open <info>%s</info> to finish implementing your user provider.',
223+
/* @phpstan-ignore-next-line - $customProviderPath is defined in this else statement */
223224
$this->fileManager->relativizePath($customProviderPath)
224225
);
225226
}

tests/Maker/FunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FunctionalTest extends TestCase
2424
* Smoke test to make sure the DI autowiring works and all makers
2525
* are registered and have the correct arguments.
2626
*/
27-
public function testWiring()
27+
public function testWiring(): void
2828
{
2929
$kernel = new MakerTestKernel('dev', true);
3030

tests/Maker/MakeEntityTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ public function getTestDetails(): \Generator
673673
];
674674
}
675675

676+
/** @param array<string, mixed> $data */
676677
private function runEntityTest(MakerTestRunner $runner, array $data = []): void
677678
{
678679
$runner->renderTemplateFile(

tests/Maker/MakeFormTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function getMakerClass(): string
2222
return MakeForm::class;
2323
}
2424

25-
public function getTestDetails()
25+
public function getTestDetails(): \Generator
2626
{
2727
yield 'it_generates_basic_form' => [$this->createMakerTest()
2828
->run(function (MakerTestRunner $runner) {
@@ -204,7 +204,7 @@ public function getTestDetails()
204204
];
205205
}
206206

207-
private function runFormTest(MakerTestRunner $runner, string $filename)
207+
private function runFormTest(MakerTestRunner $runner, string $filename): void
208208
{
209209
$runner->copy(
210210
'make-form/tests/'.$filename,

tests/Maker/MakeMessageTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private function createMakeMessageTest(): MakerTestDetails
4040
});
4141
}
4242

43-
public function getTestDetails()
43+
public function getTestDetails(): \Generator
4444
{
4545
yield 'it_generates_basic_message' => [$this->createMakeMessageTest()
4646
->run(function (MakerTestRunner $runner) {
@@ -94,7 +94,7 @@ public function getTestDetails()
9494
];
9595
}
9696

97-
private function runMessageTest(MakerTestRunner $runner, string $filename)
97+
private function runMessageTest(MakerTestRunner $runner, string $filename): void
9898
{
9999
$runner->copy(
100100
'make-message/tests/'.$filename,
@@ -104,7 +104,7 @@ private function runMessageTest(MakerTestRunner $runner, string $filename)
104104
$runner->runTests();
105105
}
106106

107-
private function configureTransports(MakerTestRunner $runner)
107+
private function configureTransports(MakerTestRunner $runner): void
108108
{
109109
$runner->writeFile(
110110
'config/packages/messenger.yaml',

tests/Maker/MakeMessengerMiddlewareTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function getMakerClass(): string
2222
return MakeMessengerMiddleware::class;
2323
}
2424

25-
public function getTestDetails()
25+
public function getTestDetails(): \Generator
2626
{
2727
yield 'it_generates_messenger_middleware' => [$this->createMakerTest()
2828
->run(function (MakerTestRunner $runner) {

tests/Maker/MakeSerializerEncoderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function getMakerClass(): string
2222
return MakeSerializerEncoder::class;
2323
}
2424

25-
public function getTestDetails()
25+
public function getTestDetails(): \Generator
2626
{
2727
yield 'it_makes_serializer_encoder' => [$this->createMakerTest()
2828
// serializer-pack 1.1 requires symfony/property-info >= 5.4

tests/Maker/MakeTwigExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function getMakerClass(): string
2222
return MakeTwigExtension::class;
2323
}
2424

25-
public function getTestDetails()
25+
public function getTestDetails(): \Generator
2626
{
2727
yield 'it_makes_twig_extension' => [$this->createMakerTest()
2828
->run(function (MakerTestRunner $runner) {

tests/Maker/MakeUnitTestTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function getMakerClass(): string
2525
return MakeUnitTest::class;
2626
}
2727

28-
public function getTestDetails()
28+
public function getTestDetails(): \Generator
2929
{
3030
yield 'it_makes_unit_test' => [$this->createMakerTest()
3131
->run(function (MakerTestRunner $runner) {

tests/Maker/MakeValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function getMakerClass(): string
2222
return MakeValidator::class;
2323
}
2424

25-
public function getTestDetails()
25+
public function getTestDetails(): \Generator
2626
{
2727
yield 'it_makes_validator' => [$this->createMakerTest()
2828
->run(function (MakerTestRunner $runner) {

tests/Maker/MakeVoterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function getMakerClass(): string
2222
return MakeVoter::class;
2323
}
2424

25-
public function getTestDetails()
25+
public function getTestDetails(): \Generator
2626
{
2727
yield 'it_makes_voter' => [$this->createMakerTest()
2828
->run(function (MakerTestRunner $runner) {

tools/phpstan/composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"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"
8+
},
9+
"config": {
10+
"allow-plugins": {
11+
"phpstan/extension-installer": true
12+
}
13+
}
14+
}

tools/phpstan/includes/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*
2+
!.gitignore
3+
!composer.json

tools/phpstan/includes/composer.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"require": {
3+
"api-platform/core": "^3.2",
4+
"doctrine/doctrine-bundle": "^2.12",
5+
"doctrine/doctrine-fixtures-bundle": "^3.5",
6+
"symfony/form": "^7.0",
7+
"symfony/mailer": "^7.0",
8+
"symfony/messenger": "^7.0",
9+
"symfony/orm-pack": "^2.4",
10+
"symfony/scheduler": "^7.0",
11+
"symfony/security-bundle": "^7.0",
12+
"symfony/test-pack": "^1.1",
13+
"symfony/twig-bundle": "^7.0",
14+
"symfony/ux-live-component": "^2.16",
15+
"symfony/ux-turbo": "^2.16",
16+
"symfony/validator": "^7.0",
17+
"symfonycasts/reset-password-bundle": "^1.21",
18+
"symfonycasts/verify-email-bundle": "^1.17",
19+
"symfony/webpack-encore-bundle": "^2.1",
20+
"symfony/panther": "^2.1"
21+
}
22+
}

0 commit comments

Comments
 (0)