From 6f7a9a1901e0b5c488ceb2fd4b338154b5e30875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Sat, 9 Dec 2023 12:16:01 +0100 Subject: [PATCH] Fix types --- Command/DoctrineODMCommand.php | 20 +++---------------- .../DoctrineMongoDBExtension.php | 12 ++++++----- Form/DoctrineMongoDBTypeGuesser.php | 2 +- Form/Type/DocumentType.php | 2 +- Loader/SymfonyFixturesLoader.php | 6 +++++- psalm-baseline.xml | 5 +++++ psalm.xml | 1 - 7 files changed, 22 insertions(+), 26 deletions(-) diff --git a/Command/DoctrineODMCommand.php b/Command/DoctrineODMCommand.php index 63b04994..dc9e3feb 100644 --- a/Command/DoctrineODMCommand.php +++ b/Command/DoctrineODMCommand.php @@ -8,7 +8,6 @@ use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Command\Command; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Base class for Doctrine ODM console commands to extend. @@ -17,32 +16,19 @@ */ abstract class DoctrineODMCommand extends Command { - /** @var ContainerInterface|null */ - protected $container; - - private ?ManagerRegistry $managerRegistry; - - public function __construct(?ManagerRegistry $registry = null) + public function __construct(private ManagerRegistry $managerRegistry) { parent::__construct(); - - $this->managerRegistry = $registry; } - /** @param string $dmName */ - public static function setApplicationDocumentManager(Application $application, $dmName) + public static function setApplicationDocumentManager(Application $application, string $dmName): void { $dm = $application->getKernel()->getContainer()->get('doctrine_mongodb')->getManager($dmName); $helperSet = $application->getHelperSet(); $helperSet->set(new DocumentManagerHelper($dm), 'dm'); } - /** - * @internal - * - * @return ManagerRegistry - */ - protected function getManagerRegistry() + protected function getManagerRegistry(): ManagerRegistry { return $this->managerRegistry; } diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index 2035405d..04e996f3 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -189,7 +189,7 @@ protected function overrideParameters($options, ContainerBuilder $container) * @param string $defaultDB The default db name * @param ContainerBuilder $container A ContainerBuilder instance */ - protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB, ContainerBuilder $container) + protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB, ContainerBuilder $container): void { $dms = []; foreach ($dmConfigs as $name => $documentManager) { @@ -213,6 +213,8 @@ protected function loadDocumentManagers(array $dmConfigs, $defaultDM, $defaultDB * @param string $defaultDM The default document manager name * @param string $defaultDB The default db name * @param ContainerBuilder $container A ContainerBuilder instance + * + * @return void */ protected function loadDocumentManager(array $documentManager, $defaultDM, $defaultDB, ContainerBuilder $container) { @@ -347,7 +349,7 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa * @param array $config An array of connections configurations * @param ContainerBuilder $container A ContainerBuilder instance */ - protected function loadConnections(array $connections, ContainerBuilder $container) + protected function loadConnections(array $connections, ContainerBuilder $container): void { $cons = []; foreach ($connections as $name => $connection) { @@ -469,7 +471,7 @@ private function normalizeDriverOptions(array $connection): array * @param ContainerBuilder $container A ContainerBuilder instance * * @example - * + * doctrine_mongodb: * mappings: * MyBundle1: ~ @@ -485,11 +487,11 @@ private function normalizeDriverOptions(array $connection): array * dir: %kernel.dir%/../src/vendor/DoctrineExtensions/lib/DoctrineExtensions/Documents * prefix: DoctrineExtensions\Documents\ * alias: DExt - * + * In the case of bundles everything is really optional (which leads to autodetection for this bundle) but * in the mappings key everything except alias is a required argument. */ - protected function loadDocumentManagerBundlesMappingInformation(array $documentManager, Definition $odmConfigDef, ContainerBuilder $container) + protected function loadDocumentManagerBundlesMappingInformation(array $documentManager, Definition $odmConfigDef, ContainerBuilder $container): void { // reset state of drivers and alias map. They are only used by this methods and children. $this->drivers = []; diff --git a/Form/DoctrineMongoDBTypeGuesser.php b/Form/DoctrineMongoDBTypeGuesser.php index e7d20967..3a7b8037 100644 --- a/Form/DoctrineMongoDBTypeGuesser.php +++ b/Form/DoctrineMongoDBTypeGuesser.php @@ -143,7 +143,7 @@ public function guessMaxLength(string $class, string $property): ?ValueGuess /** * {@inheritDoc} */ - public function guessMinLength($class, $property) + public function guessMinLength($class, $property): void { } diff --git a/Form/Type/DocumentType.php b/Form/Type/DocumentType.php index fe708c39..ef21aa70 100644 --- a/Form/Type/DocumentType.php +++ b/Form/Type/DocumentType.php @@ -37,7 +37,7 @@ public function configureOptions(OptionsResolver $resolver): void $resolver->setDefaults(['document_manager' => null]); $registry = $this->registry; - $normalizer = static function (Options $options, $manager) use ($registry) { + $normalizer = static function (Options $options, $manager) use ($registry): ObjectManager|null { if (isset($options['document_manager']) && $manager) { throw new InvalidArgumentException('You cannot set both an "em" and "document_manager" option.'); } diff --git a/Loader/SymfonyFixturesLoader.php b/Loader/SymfonyFixturesLoader.php index bb75b2a5..8ffac080 100644 --- a/Loader/SymfonyFixturesLoader.php +++ b/Loader/SymfonyFixturesLoader.php @@ -140,7 +140,11 @@ private function addGroupsFixtureMapping(string $className, array $groups): void } } - /** @param array, FixtureInterface> $fixtures An array of fixtures with class names as keys */ + /** + * @param array, FixtureInterface> $fixtures An array of fixtures with class names as keys + * + * @return void + */ private function validateDependencies(array $fixtures, FixtureInterface $fixture) { if (! $fixture instanceof DependentFixtureInterface) { diff --git a/psalm-baseline.xml b/psalm-baseline.xml index bc24f184..aed4f782 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -16,6 +16,11 @@ children + + + ?TypeGuess + + private ContainerInterface $container diff --git a/psalm.xml b/psalm.xml index 6659793d..da0596c9 100644 --- a/psalm.xml +++ b/psalm.xml @@ -16,7 +16,6 @@ -