From bf2c9d189813c0fdd277a013ed63e58cc222f19a Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Tue, 24 Sep 2024 16:29:17 +0200 Subject: [PATCH 1/4] Add proper support for DQL types in PHPStan Doctrine --- CHANGELOG.md | 6 ++++++ _init/symfony/phpstan.neon | 6 +++++- .../tests/phpstan-doctrine-object-manager.php | 13 +++++++++++++ phpstan/symfony.neon | 6 ++++++ 4 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 _init/symfony/tests/phpstan-doctrine-object-manager.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 95fdff0..50dbf5b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +1.3.5 +===== + +* (improvement) Add proper support for DQL types in PHPStan Doctrine. + + 1.3.4 ===== diff --git a/_init/symfony/phpstan.neon b/_init/symfony/phpstan.neon index bd86715..9556395 100644 --- a/_init/symfony/phpstan.neon +++ b/_init/symfony/phpstan.neon @@ -1,8 +1,12 @@ includes: - vendor/21torr/janus/phpstan/symfony.neon + +parameters: + doctrine: + objectManagerLoader: tests/phpstan-doctrine-object-manager.php + # If you use simple-phpunit, you need to uncomment the following line. # Always make sure to first run simple-phpunit and then PHPStan. -# parameters: # bootstrapFiles: # - vendor/bin/.phpunit/phpunit/vendor/autoload.php diff --git a/_init/symfony/tests/phpstan-doctrine-object-manager.php b/_init/symfony/tests/phpstan-doctrine-object-manager.php new file mode 100644 index 0000000..68b7eb5 --- /dev/null +++ b/_init/symfony/tests/phpstan-doctrine-object-manager.php @@ -0,0 +1,13 @@ +bootEnv(__DIR__ . '/../.env'); + +$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); +$kernel->boot(); + +return $kernel->getContainer()->get('doctrine')->getManager(); diff --git a/phpstan/symfony.neon b/phpstan/symfony.neon index 0f80968..2d8c05f 100644 --- a/phpstan/symfony.neon +++ b/phpstan/symfony.neon @@ -4,3 +4,9 @@ includes: parameters: symfony: container_xml_path: %currentWorkingDirectory%/var/cache/dev/App_KernelDevDebugContainer.xml + + ignoreErrors: + # We will always have the issue, that the type of the prop and the database type won't match, + # as we validate in between and PHPStan can't know that. So let's just deactivate it. + - identifier: doctrine.columnType + From 91f6da622e0ab185934177f13824158fbf34f52e Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Tue, 24 Sep 2024 16:38:14 +0200 Subject: [PATCH 2/4] Ignore return type of Storyblok stories for now --- CHANGELOG.md | 1 + phpstan/symfony.neon | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50dbf5b..a56f5c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ===== * (improvement) Add proper support for DQL types in PHPStan Doctrine. +* (improvement) Ignore return type of Storyblok stories for now. 1.3.4 diff --git a/phpstan/symfony.neon b/phpstan/symfony.neon index 2d8c05f..fb0e797 100644 --- a/phpstan/symfony.neon +++ b/phpstan/symfony.neon @@ -10,3 +10,7 @@ parameters: # as we validate in between and PHPStan can't know that. So let's just deactivate it. - identifier: doctrine.columnType + # Let's ignore return types of Storyblok stories for now + - + identifier: return.type + path: %currentWorkingDirectory%/src/Storyblok/Component/*Story.php From bf77893581e05307223d8a6c5d8d3a905c8d3c0f Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Tue, 24 Sep 2024 16:47:58 +0200 Subject: [PATCH 3/4] Fix CI --- src/Initializer/InitializeHelper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Initializer/InitializeHelper.php b/src/Initializer/InitializeHelper.php index ea8f1ff..4a3ab6a 100644 --- a/src/Initializer/InitializeHelper.php +++ b/src/Initializer/InitializeHelper.php @@ -157,7 +157,7 @@ public function runComposerInProject (array $cmd) : void */ public function runProcessInProject (array $cmd) : void { - $this->io->writeln(sprintf( + $this->io->writeln(\sprintf( "$> Running command %s", implode(" ", $cmd), )); @@ -168,12 +168,12 @@ public function runProcessInProject (array $cmd) : void ); $process->mustRun(); - $output = trim(sprintf("%s\n%s", $process->getErrorOutput(), $process->getOutput())); + $output = trim(\sprintf("%s\n%s", $process->getErrorOutput(), $process->getOutput())); if ("" !== $output) { $this->io->block( - trim(sprintf("%s\n%s", $process->getErrorOutput(), $process->getOutput())), + trim(\sprintf("%s\n%s", $process->getErrorOutput(), $process->getOutput())), prefix: " │ ", ); } From 24c1cbeb31d2ef05183eabff34dee60cbc114674 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Tue, 24 Sep 2024 18:35:55 +0200 Subject: [PATCH 4/4] Ignore file in phpstan --- phpstan.neon | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index 221849f..286f317 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,2 +1,7 @@ includes: - - phpstan/lib.neon + - phpstan/lib.neon + +parameters: + excludePaths: + analyseAndScan: + - _init/symfony/tests/phpstan-doctrine-object-manager.php