From 934d2668808b1c621191896dceb5383a28327c60 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 19 Jul 2021 19:59:41 +0200 Subject: [PATCH] Added phpstan-symfony plugin to improve inspections on getArgument and getOption --- bin/cli | 7 +++++-- composer.json | 3 ++- config/cli-app.php | 12 ++++++++++++ config/cli-config.php | 2 +- config/run.php | 5 ++--- phpstan.neon | 4 ++++ public/index.php | 3 +-- 7 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 config/cli-app.php diff --git a/bin/cli b/bin/cli index c185efd3..56437c8b 100755 --- a/bin/cli +++ b/bin/cli @@ -3,5 +3,8 @@ declare(strict_types=1); -$run = require __DIR__ . '/../config/run.php'; -$run(true); +use Symfony\Component\Console\Application; + +/** @var Application $app */ +$app = require __DIR__ . '/../config/cli-app.php'; +$app->run(); diff --git a/composer.json b/composer.json index abf44182..bc4806b1 100644 --- a/composer.json +++ b/composer.json @@ -66,7 +66,8 @@ "eaglewu/swoole-ide-helper": "dev-master", "infection/infection": "^0.21.0", "phpspec/prophecy-phpunit": "^2.0", - "phpstan/phpstan": "^0.12.64", + "phpstan/phpstan": "^0.12.92", + "phpstan/phpstan-symfony": "^0.12.41", "phpunit/php-code-coverage": "^9.2", "phpunit/phpunit": "^9.5", "roave/security-advisories": "dev-master", diff --git a/config/cli-app.php b/config/cli-app.php new file mode 100644 index 00000000..a2272852 --- /dev/null +++ b/config/cli-app.php @@ -0,0 +1,12 @@ +get(CliApp::class); +})(); diff --git a/config/cli-config.php b/config/cli-config.php index 71c7a75e..396fc075 100644 --- a/config/cli-config.php +++ b/config/cli-config.php @@ -6,7 +6,7 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\Console\ConsoleRunner; use Psr\Container\ContainerInterface; -return (function () { +return (static function () { /** @var ContainerInterface $container */ $container = include __DIR__ . '/container.php'; $em = $container->get(EntityManager::class); diff --git a/config/run.php b/config/run.php index 80116e24..5de0df16 100644 --- a/config/run.php +++ b/config/run.php @@ -4,12 +4,11 @@ declare(strict_types=1); use Mezzio\Application; use Psr\Container\ContainerInterface; -use Symfony\Component\Console\Application as CliApp; -return function (bool $isCli = false): void { +return static function (): void { /** @var ContainerInterface $container */ $container = include __DIR__ . '/container.php'; - $app = $container->get($isCli ? CliApp::class : Application::class); + $app = $container->get(Application::class); $app->run(); }; diff --git a/phpstan.neon b/phpstan.neon index 80f1b083..eb98657e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,9 @@ +includes: + - vendor/phpstan/phpstan-symfony/extension.neon parameters: checkMissingIterableValueType: false checkGenericClassInNonGenericObjectType: false ignoreErrors: - '#If condition is always false#' + symfony: + console_application_loader: 'config/cli-app.php' diff --git a/public/index.php b/public/index.php index 78bb412a..99018890 100644 --- a/public/index.php +++ b/public/index.php @@ -2,5 +2,4 @@ declare(strict_types=1); -$run = require __DIR__ . '/../config/run.php'; -$run(); +(require __DIR__ . '/../config/run.php')();