Skip to content

Commit

Permalink
Upgrade to PHPStan 2
Browse files Browse the repository at this point in the history
  • Loading branch information
rosier committed Dec 11, 2024
1 parent 3277fc2 commit 90851bc
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 79 deletions.
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 -v
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: 21 additions & 49 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,71 +1,43 @@
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: '#^Class App\\Form\\ChangePasswordType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Entity/Comment.php
path: src/Form/ChangePasswordType.php

-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
message: '#^Class App\\Form\\CommentType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Entity/Comment.php
path: src/Form/CommentType.php

-
message: "#^Property App\\\\Entity\\\\Comment\\:\\:\\$post type mapping mismatch\\: property can contain App\\\\Entity\\\\Post\\|null but database expects App\\\\Entity\\\\Post\\.$#"
message: '#^Class App\\Form\\PostType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Entity/Comment.php
path: src/Form/PostType.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$author type mapping mismatch\\: property can contain App\\\\Entity\\\\User\\|null but database expects App\\\\Entity\\\\User\\.$#"
message: '#^Class App\\Form\\Type\\DateTimePickerType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Entity/Post.php
path: src/Form/Type/DateTimePickerType.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$content type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
message: '#^Class App\\Form\\Type\\TagsInputType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Entity/Post.php
path: src/Form/Type/TagsInputType.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$slug type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
message: '#^Class App\\Form\\UserType extends generic class Symfony\\Component\\Form\\AbstractType but does not specify its types\: TData$#'
identifier: missingType.generics
count: 1
path: src/Entity/Post.php
path: src/Form/UserType.php

-
message: "#^Property App\\\\Entity\\\\Post\\:\\:\\$summary type mapping mismatch\\: property can contain string\\|null but database expects string\\.$#"
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/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
15 changes: 15 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
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

level: 6
paths:
- 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

0 comments on commit 90851bc

Please sign in to comment.