diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index d748c5969..6e26e4075 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -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' @@ -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 diff --git a/composer.json b/composer.json index c0cad52e6..d7f006f9b 100644 --- a/composer.json +++ b/composer.json @@ -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", @@ -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" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e6ff909a9..0510e0ed5 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/phpstan.dist.neon b/phpstan.dist.neon index e0de575fd..6eec145fc 100644 --- a/phpstan.dist.neon +++ b/phpstan.dist.neon @@ -1,4 +1,16 @@ +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/ @@ -6,3 +18,6 @@ parameters: - public/ - src/ - tests/ + + symfony: + containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml diff --git a/phpstan.neon.dist b/phpstan.neon.dist deleted file mode 100644 index 5676dc5d6..000000000 --- a/phpstan.neon.dist +++ /dev/null @@ -1,14 +0,0 @@ -includes: - - phpstan-baseline.neon - -parameters: - level: max - paths: - - src - - tests - bootstrapFiles: - - vendor/bin/.phpunit/phpunit/vendor/autoload.php - doctrine: - objectManagerLoader: tests/object-manager.php - symfony: - containerXmlPath: var/cache/dev/App_KernelDevDebugContainer.xml diff --git a/src/Form/Type/DateTimePickerType.php b/src/Form/Type/DateTimePickerType.php index 7dddd8182..81223c2ae 100644 --- a/src/Form/Type/DateTimePickerType.php +++ b/src/Form/Type/DateTimePickerType.php @@ -49,7 +49,7 @@ public function configureOptions(OptionsResolver $resolver): void ]); } - public function getParent(): ?string + public function getParent(): string { return DateTimeType::class; } diff --git a/src/Form/Type/TagsInputType.php b/src/Form/Type/TagsInputType.php index 82ed6320d..60ca16570 100644 --- a/src/Form/Type/TagsInputType.php +++ b/src/Form/Type/TagsInputType.php @@ -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; } diff --git a/tests/Controller/Admin/BlogControllerTest.php b/tests/Controller/Admin/BlogControllerTest.php index 7f3618da2..0774b86bb 100644 --- a/tests/Controller/Admin/BlogControllerTest.php +++ b/tests/Controller/Admin/BlogControllerTest.php @@ -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); diff --git a/tests/Controller/UserControllerTest.php b/tests/Controller/UserControllerTest.php index 5ec58d0f6..f333d6ea6 100644 --- a/tests/Controller/UserControllerTest.php +++ b/tests/Controller/UserControllerTest.php @@ -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);