From 119c27d32753f6ba54a56f441673242ff191444b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ostroluck=C3=BD?= Date: Tue, 14 Jan 2025 09:54:45 +0100 Subject: [PATCH] phpstan: lvl 1 -> 2 --- phpstan.neon.dist | 13 ++++++++++++- src/Command/DoctrineCommand.php | 3 --- src/Command/ImportMappingDoctrineCommand.php | 6 +++++- src/ConnectionFactory.php | 2 +- src/Registry.php | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c7d831239..16a8eab86 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - level: 1 + level: 2 paths: - src - tests @@ -7,3 +7,14 @@ parameters: excludePaths: - src/Command/Proxy/ConvertMappingDoctrineCommand.php - src/Command/Proxy/EnsureProductionSettingsDoctrineCommand.php + ignoreErrors: + # Available in ORM < 3 only + - '#Doctrine\\ORM\\Tools\\EntityGenerator.#' + - '#Doctrine\\ORM\\Tools\\DisconnectedClassMetadataFactory.#' + - '#Doctrine\\ORM\\Tools\\Export\\ClassMetadataExporter.#' + # phpstan has no array shape intersection support https://github.com/phpstan/phpstan/issues/12414 + - message: '#unresolvable type.#' + path: src/DataCollector/DoctrineDataCollector.php + # Probably needs Symfony plugin + - message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\Node#' + path: src/DependencyInjection/Configuration.php diff --git a/src/Command/DoctrineCommand.php b/src/Command/DoctrineCommand.php index da787f7ac..0e7c25d12 100644 --- a/src/Command/DoctrineCommand.php +++ b/src/Command/DoctrineCommand.php @@ -29,12 +29,9 @@ public function __construct(ManagerRegistry $doctrine) * get a doctrine entity generator * * @return EntityGenerator - * - * @psalm-suppress UndefinedDocblockClass ORM < 3 specific */ protected function getEntityGenerator() { - /** @phpstan-ignore class.notFound */ $entityGenerator = new EntityGenerator(); $entityGenerator->setGenerateAnnotations(false); $entityGenerator->setGenerateStubMethods(true); diff --git a/src/Command/ImportMappingDoctrineCommand.php b/src/Command/ImportMappingDoctrineCommand.php index 44ca44651..28a68d8ac 100644 --- a/src/Command/ImportMappingDoctrineCommand.php +++ b/src/Command/ImportMappingDoctrineCommand.php @@ -2,6 +2,7 @@ namespace Doctrine\Bundle\DoctrineBundle\Command; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\Driver\DatabaseDriver; use Doctrine\ORM\Tools\Console\MetadataFilter; use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory; @@ -13,6 +14,7 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use function assert; use function chmod; use function dirname; use function file_put_contents; @@ -91,6 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $namespaceOrBundle = $input->getArgument('name'); if (isset($this->bundles[$namespaceOrBundle])) { + /** @phpstan-ignore method.notFound */ $bundle = $this->getApplication()->getKernel()->getBundle($namespaceOrBundle); $namespace = $bundle->getNamespace() . '\Entity'; @@ -121,13 +124,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $em = $this->getEntityManager($input->getOption('em')); + /* @phpstan-ignore method.notFound (Available in DBAL < 4) */ $databaseDriver = new DatabaseDriver($em->getConnection()->getSchemaManager()); $em->getConfiguration()->setMetadataDriverImpl($databaseDriver); $emName = $input->getOption('em'); $emName = $emName ? $emName : 'default'; - /* @phpstan-ignore class.notFound */ $cmf = new DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); $metadata = $cmf->getAllMetadata(); @@ -135,6 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int if ($metadata) { $output->writeln(sprintf('Importing mapping information from "%s" entity manager', $emName)); foreach ($metadata as $class) { + assert($class instanceof ClassMetadata); $className = $class->name; $class->name = $namespace . '\\' . $className; if ($type === 'annotation') { diff --git a/src/ConnectionFactory.php b/src/ConnectionFactory.php index d762963b0..4e9e3bef9 100644 --- a/src/ConnectionFactory.php +++ b/src/ConnectionFactory.php @@ -119,7 +119,7 @@ public function createConnection(array $params, ?Configuration $config = null, ? $connection = DriverManager::getConnection(...array_merge([$params, $config], $eventManager ? [$eventManager] : [])); $params = $this->addDatabaseSuffix(array_merge($connection->getParams(), $overriddenOptions)); $driver = $connection->getDriver(); - /** @psalm-suppress InvalidScalarArgument Bogus error, StaticServerVersionProvider implements Doctrine\DBAL\ServerVersionProvider */ + /** @phpstan-ignore arguments.count (DBAL < 4.x doesn't accept an argument) */ $platform = $driver->getDatabasePlatform( ...(class_exists(StaticServerVersionProvider::class) ? [new StaticServerVersionProvider($params['serverVersion'] ?? $params['primary']['serverVersion'] ?? '')] diff --git a/src/Registry.php b/src/Registry.php index 958956dc3..c24da6643 100644 --- a/src/Registry.php +++ b/src/Registry.php @@ -51,7 +51,7 @@ public function getAliasNamespace($alias) } try { - /** @psalm-suppress UndefinedMethod ORM < 3 specific */ + /** @phpstan-ignore method.notFound (ORM < 3 specific) */ return $objectManager->getConfiguration()->getEntityNamespace($alias); /* @phpstan-ignore class.notFound */ } catch (ORMException $e) {