diff --git a/composer.json b/composer.json index e76c937eb..7732b5f39 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "cakephp/database": "^5.0.2", "psr/container": "^1.1|^2.0", "symfony/config": "^4.0|^5.0|^6.0|^7.0|^8.0", - "symfony/console": "^6.0|^7.0" + "symfony/console": "^6.0|^7.0|^8.0" }, "require-dev": { "ext-json": "*", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e94c74dde..d5bdae97f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4,3 +4,9 @@ parameters: message: "#^Expression on left side of \\?\\? is not nullable\\.$#" count: 1 path: src/Phinx/Db/Adapter/MysqlAdapter.php + + - + message: "#^Call to an undefined static method Symfony\\\\Component\\\\Console\\\\Application\\:\\:addCommand\\(\\)\\.$#" + count: 1 + path: src/Phinx/Console/PhinxApplication.php + reportUnmatched: false diff --git a/src/Phinx/Console/PhinxApplication.php b/src/Phinx/Console/PhinxApplication.php index a5f523b21..8145fc161 100644 --- a/src/Phinx/Console/PhinxApplication.php +++ b/src/Phinx/Console/PhinxApplication.php @@ -20,6 +20,7 @@ use Phinx\Console\Command\Status; use Phinx\Console\Command\Test; use Symfony\Component\Console\Application; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputDefinition; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -90,6 +91,25 @@ public function doRun(InputInterface $input, OutputInterface $output): int return parent::doRun($input, $output); } + /** + * Adds a command object. + * + * Provides backwards compatibility for Symfony Console 6.x/7.x where + * the add() method exists, and Symfony 8.x where it was removed in + * favor of addCommand(). + * + * @param \Symfony\Component\Console\Command\Command $command A Command object + * @return \Symfony\Component\Console\Command\Command|null + */ + public function add(Command $command): ?Command + { + if (method_exists(Application::class, 'addCommand')) { + return parent::addCommand($command); + } + + return parent::add($command); + } + /** * Get the current application version. *