Skip to content

Commit

Permalink
Merge pull request #16 from 21TORR/doctrine-dql
Browse files Browse the repository at this point in the history
Improve PHPStan support of Doctrine DQL + ignore Storybloks story return types
  • Loading branch information
apfelbox authored Sep 30, 2024
2 parents 831bdbf + 24c1cbe commit 5263c4b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.3.5
=====

* (improvement) Add proper support for DQL types in PHPStan Doctrine.
* (improvement) Ignore return type of Storyblok stories for now.


1.3.4
=====

Expand Down
6 changes: 5 additions & 1 deletion _init/symfony/phpstan.neon
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions _init/symfony/tests/phpstan-doctrine-object-manager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types=1);

use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;

require __DIR__ . '/../vendor/autoload.php';

(new Dotenv())->bootEnv(__DIR__ . '/../.env');

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();

return $kernel->getContainer()->get('doctrine')->getManager();
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
includes:
- phpstan/lib.neon
- phpstan/lib.neon

parameters:
excludePaths:
analyseAndScan:
- _init/symfony/tests/phpstan-doctrine-object-manager.php
10 changes: 10 additions & 0 deletions phpstan/symfony.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,13 @@ 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

# Let's ignore return types of Storyblok stories for now
-
identifier: return.type
path: %currentWorkingDirectory%/src/Storyblok/Component/*Story.php
6 changes: 3 additions & 3 deletions src/Initializer/InitializeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <fg=blue>%s</>",
implode(" ", $cmd),
));
Expand All @@ -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: "",
);
}
Expand Down

0 comments on commit 5263c4b

Please sign in to comment.