diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 7fa581bb..0adedf31 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -84,6 +84,12 @@ parameters: count: 1 path: src/Command/LoadDataFixturesDoctrineODMCommand.php + - + message: '#^Method Psr\\Log\\AbstractLogger@anonymous/src/Command/LoadDataFixturesDoctrineODMCommand\.php\:89\:\:log\(\) has parameter \$message with no type specified\.$#' + identifier: missingType.parameter + count: 1 + path: src/Command/LoadDataFixturesDoctrineODMCommand.php + - message: '#^Parameter \#1 \$dm of class Doctrine\\Common\\DataFixtures\\Executor\\MongoDBExecutor constructor expects Doctrine\\ODM\\MongoDB\\DocumentManager, Doctrine\\Persistence\\ObjectManager given\.$#' identifier: argument.type diff --git a/src/Command/LoadDataFixturesDoctrineODMCommand.php b/src/Command/LoadDataFixturesDoctrineODMCommand.php index 38897d50..34e0f66c 100644 --- a/src/Command/LoadDataFixturesDoctrineODMCommand.php +++ b/src/Command/LoadDataFixturesDoctrineODMCommand.php @@ -8,6 +8,8 @@ use Doctrine\Bundle\MongoDBBundle\ManagerRegistry; use Doctrine\Common\DataFixtures\Executor\MongoDBExecutor; use Doctrine\Common\DataFixtures\Purger\MongoDBPurger; +use Psr\Log\AbstractLogger; +use Stringable; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -83,8 +85,23 @@ protected function execute(InputInterface $input, OutputInterface $output): int $purger = new MongoDBPurger($dm); $executor = new MongoDBExecutor($dm, $purger); - $executor->setLogger(static function ($message) use ($output): void { - $output->writeln(sprintf(' > %s', $message)); + + $executor->setLogger(new class ($output) extends AbstractLogger { + public function __construct(private OutputInterface $output) + { + } + + /** {@inheritDoc} */ + public function log($level, $message, array $context = []): void + { + $this->output->writeln(sprintf(' > %s', $message)); + } + + /** @deprecated to be removed when dropping support for doctrine/data-fixtures <1.8 */ + public function __invoke(string $message): void + { + $this->log(0, $message); + } }); $executor->execute($fixtures, $input->getOption('append'));