Skip to content

Commit 5dc439e

Browse files
committed
Upgrade to PHPStan 2
1 parent 3277fc2 commit 5dc439e

File tree

9 files changed

+54
-102
lines changed

9 files changed

+54
-102
lines changed

Diff for: .github/workflows/lint.yaml

+22-6
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ jobs:
5656
restore-keys: ${{ runner.os }}-composer-
5757

5858
- name: "Install dependencies"
59-
run: composer install --ansi --no-interaction --no-progress
60-
61-
- name: Install PHPUnit
6259
id: install
63-
run: vendor/bin/simple-phpunit install
60+
run: composer install --ansi --no-interaction --no-progress
6461

6562
- name: Lint YAML files
6663
if: always() && steps.install.outcome == 'success'
@@ -94,6 +91,25 @@ jobs:
9491
if: always() && steps.install.outcome == 'success'
9592
run: composer audit
9693

94+
static-analysis:
95+
name: PHPStan
96+
runs-on: ubuntu-latest
97+
98+
steps:
99+
- name: Checkout code
100+
uses: actions/checkout@v4
101+
102+
- name: Setup PHP
103+
uses: shivammathur/setup-php@v2
104+
with:
105+
coverage: none
106+
php-version: '8.3'
107+
108+
- name: Install dependencies
109+
run: composer install --ansi --no-interaction --no-progress
110+
111+
- name: Install PHPUnit
112+
run: vendor/bin/simple-phpunit install
113+
97114
- name: Run PHPStan
98-
if: always() && steps.install.outcome == 'success'
99-
run: ./vendor/bin/phpstan analyze
115+
run: vendor/bin/phpstan analyze --no-progress

Diff for: composer.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@
5454
"require-dev": {
5555
"dama/doctrine-test-bundle": "^8.0.2",
5656
"doctrine/doctrine-fixtures-bundle": "^3.5",
57-
"phpstan/extension-installer": "^1.2",
58-
"phpstan/phpstan": "^1.2",
59-
"phpstan/phpstan-doctrine": "^1.3",
60-
"phpstan/phpstan-symfony": "^1.2",
57+
"phpstan/phpstan": "^2.0",
58+
"phpstan/phpstan-doctrine": "^2.0",
59+
"phpstan/phpstan-symfony": "^2.0",
6160
"symfony/browser-kit": "^7",
6261
"symfony/css-selector": "^7",
6362
"symfony/debug-bundle": "^7",
@@ -70,8 +69,7 @@
7069
"config": {
7170
"allow-plugins": {
7271
"symfony/flex": true,
73-
"symfony/runtime": true,
74-
"phpstan/extension-installer": true
72+
"symfony/runtime": true
7573
},
7674
"platform": {
7775
"php": "8.2.0"

Diff for: phpstan-baseline.neon

+3-67
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,7 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
4+
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Component\\\\Dotenv\\\\Dotenv'' and ''bootEnv'' will always evaluate to true\.$#'
5+
identifier: function.alreadyNarrowedType
56
count: 1
6-
path: src/Entity/Comment.php
7-
8-
-
9-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
10-
count: 1
11-
path: src/Entity/Comment.php
12-
13-
-
14-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$post type mapping mismatch\\: property can contain App\\\\Entity\\\\Post\\|null but database expects App\\\\Entity\\\\Post\\.$#"
15-
count: 1
16-
path: src/Entity/Comment.php
17-
18-
-
19-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
20-
count: 1
21-
path: src/Entity/Post.php
22-
23-
-
24-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
25-
count: 1
26-
path: src/Entity/Post.php
27-
28-
-
29-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$slug type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
30-
count: 1
31-
path: src/Entity/Post.php
32-
33-
-
34-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$summary type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
35-
count: 1
36-
path: src/Entity/Post.php
37-
38-
-
39-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$title type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
40-
count: 1
41-
path: src/Entity/Post.php
42-
43-
-
44-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$email type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
45-
count: 1
46-
path: src/Entity/User.php
47-
48-
-
49-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$fullName type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
50-
count: 1
51-
path: src/Entity/User.php
52-
53-
-
54-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$password type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
55-
count: 1
56-
path: src/Entity/User.php
57-
58-
-
59-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$username type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
60-
count: 1
61-
path: src/Entity/User.php
62-
63-
-
64-
message: "#^Method App\\\\Entity\\\\User::getUserIdentifier\\(\\) should return non-empty-string but returns string\\.$#"
65-
count: 1
66-
path: src/Entity/User.php
67-
68-
-
69-
message: "#^Parameter \\#1 \\$function of class ReflectionFunction constructor expects Closure\\|string, callable\\(\\)\\: mixed given\\.$#"
70-
count: 1
71-
path: src/Twig/SourceCodeExtension.php
7+
path: tests/bootstrap.php

Diff for: phpstan.dist.neon

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,26 @@
1+
includes:
2+
- phpstan-baseline.neon
3+
- vendor/phpstan/phpstan-doctrine/extension.neon
4+
- vendor/phpstan/phpstan-symfony/extension.neon
5+
- vendor/phpstan/phpstan-symfony/rules.neon
6+
17
parameters:
8+
bootstrapFiles:
9+
- vendor/bin/.phpunit/phpunit/vendor/autoload.php
10+
11+
doctrine:
12+
objectManagerLoader: tests/object-manager.php
13+
14+
ignoreErrors:
15+
- identifier: missingType.generics
16+
217
level: 6
318
paths:
4-
- bin/
5-
- config/
6-
- public/
7-
- src/
8-
- tests/
19+
- bin
20+
- config
21+
- public
22+
- src
23+
- tests
24+
25+
symfony:
26+
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml

Diff for: phpstan.neon.dist

-14
This file was deleted.

Diff for: src/Form/Type/DateTimePickerType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function configureOptions(OptionsResolver $resolver): void
4949
]);
5050
}
5151

52-
public function getParent(): ?string
52+
public function getParent(): string
5353
{
5454
return DateTimeType::class;
5555
}

Diff for: src/Form/Type/TagsInputType.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
5252
$view->vars['tags'] = $this->tags->findAll();
5353
}
5454

55-
public function getParent(): ?string
55+
public function getParent(): string
5656
{
5757
return TextType::class;
5858
}

Diff for: tests/Controller/Admin/BlogControllerTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public function testAdminNewPost(): void
110110
/** @var PostRepository $postRepository */
111111
$postRepository = static::getContainer()->get(PostRepository::class);
112112

113-
/** @var \App\Entity\Post $post */
114113
$post = $postRepository->findOneByTitle($postTitle);
115114

116115
$this->assertNotNull($post);

Diff for: tests/Controller/UserControllerTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public function testEditUser(): void
7575

7676
$this->assertResponseRedirects('/en/profile/edit', Response::HTTP_SEE_OTHER);
7777

78-
/** @var User $user */
7978
$user = $userRepository->findOneByEmail($newUserEmail);
8079

8180
$this->assertNotNull($user);

0 commit comments

Comments
 (0)