Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to PHPStan 2 #1547

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ jobs:
restore-keys: ${{ runner.os }}-composer-

- name: "Install dependencies"
run: composer install --ansi --no-interaction --no-progress

- name: Install PHPUnit
id: install
run: vendor/bin/simple-phpunit install
run: composer install --ansi --no-interaction --no-progress

- name: Lint YAML files
if: always() && steps.install.outcome == 'success'
Expand Down Expand Up @@ -94,6 +91,25 @@ jobs:
if: always() && steps.install.outcome == 'success'
run: composer audit

static-analysis:
name: PHPStan
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
coverage: none
php-version: '8.3'

- name: Install dependencies
run: composer install --ansi --no-interaction --no-progress

- name: Install PHPUnit
run: vendor/bin/simple-phpunit install

- name: Run PHPStan
if: always() && steps.install.outcome == 'success'
run: ./vendor/bin/phpstan analyze
run: vendor/bin/phpstan analyze --no-progress
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@
"require-dev": {
"dama/doctrine-test-bundle": "^8.0.2",
"doctrine/doctrine-fixtures-bundle": "^3.5",
"phpstan/extension-installer": "^1.2",
"phpstan/phpstan": "^1.2",
"phpstan/phpstan-doctrine": "^1.3",
"phpstan/phpstan-symfony": "^1.2",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-doctrine": "^2.0",
"phpstan/phpstan-symfony": "^2.0",
"symfony/browser-kit": "^7",
"symfony/css-selector": "^7",
"symfony/debug-bundle": "^7",
Expand All @@ -70,8 +69,7 @@
"config": {
"allow-plugins": {
"symfony/flex": true,
"symfony/runtime": true,
"phpstan/extension-installer": true
"symfony/runtime": true
},
"platform": {
"php": "8.2.0"
Expand Down
70 changes: 3 additions & 67 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,71 +1,7 @@
parameters:
ignoreErrors:
-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
message: '#^Call to function method_exists\(\) with ''Symfony\\\\Component\\\\Dotenv\\\\Dotenv'' and ''bootEnv'' will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/Entity/Comment.php

-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Comment.php

-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$post type mapping mismatch\\: property can contain App\\\\Entity\\\\Post\\|null but database expects App\\\\Entity\\\\Post\\.$#"
count: 1
path: src/Entity/Comment.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$slug type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$summary type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$title type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/Post.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$email type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$fullName type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$password type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Property App\\\\Entity\\\\User\\:\\:\\$username type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Method App\\\\Entity\\\\User::getUserIdentifier\\(\\) should return non-empty-string but returns string\\.$#"
count: 1
path: src/Entity/User.php

-
message: "#^Parameter \\#1 \\$function of class ReflectionFunction constructor expects Closure\\|string, callable\\(\\)\\: mixed given\\.$#"
count: 1
path: src/Twig/SourceCodeExtension.php
path: tests/bootstrap.php
28 changes: 23 additions & 5 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
includes:
- phpstan-baseline.neon
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-symfony/extension.neon
- vendor/phpstan/phpstan-symfony/rules.neon

parameters:
bootstrapFiles:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php

doctrine:
objectManagerLoader: tests/object-manager.php

ignoreErrors:
- identifier: missingType.generics

level: 6
paths:
- bin/
- config/
- public/
- src/
- tests/
- bin
- config
- public
- src
- tests

symfony:
containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml
14 changes: 0 additions & 14 deletions phpstan.neon.dist

This file was deleted.

2 changes: 1 addition & 1 deletion src/Form/Type/DateTimePickerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function configureOptions(OptionsResolver $resolver): void
]);
}

public function getParent(): ?string
public function getParent(): string
{
return DateTimeType::class;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Type/TagsInputType.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function buildView(FormView $view, FormInterface $form, array $options):
$view->vars['tags'] = $this->tags->findAll();
}

public function getParent(): ?string
public function getParent(): string
{
return TextType::class;
}
Expand Down
1 change: 0 additions & 1 deletion tests/Controller/Admin/BlogControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public function testAdminNewPost(): void
/** @var PostRepository $postRepository */
$postRepository = static::getContainer()->get(PostRepository::class);

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

$this->assertNotNull($post);
Expand Down
1 change: 0 additions & 1 deletion tests/Controller/UserControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public function testEditUser(): void

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

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

$this->assertNotNull($user);
Expand Down
Loading