From 58f2d3ac539f9afec4d5c969c8a086d3fc93cdd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Sat, 9 Dec 2023 18:28:34 +0100 Subject: [PATCH 1/2] Add native return types --- CacheWarmer/ProxyCacheWarmer.php | 2 +- .../Compiler/CreateHydratorDirectoryPass.php | 3 +-- .../Compiler/CreateProxyDirectoryPass.php | 3 +-- .../Compiler/FixturesCompilerPass.php | 3 +-- .../Compiler/ServiceRepositoryCompilerPass.php | 3 +-- DependencyInjection/Configuration.php | 14 ++++++-------- DependencyInjection/DoctrineMongoDBExtension.php | 6 ++---- Form/DoctrineMongoDBTypeGuesser.php | 2 +- Form/Type/DocumentType.php | 3 +-- 9 files changed, 15 insertions(+), 24 deletions(-) diff --git a/CacheWarmer/ProxyCacheWarmer.php b/CacheWarmer/ProxyCacheWarmer.php index 3ca8f574..c6eec363 100644 --- a/CacheWarmer/ProxyCacheWarmer.php +++ b/CacheWarmer/ProxyCacheWarmer.php @@ -76,7 +76,7 @@ public function warmUp(string $cacheDir, ?string $buildDir = null) } /** @return ClassMetadata[] */ - private function getClassesForProxyGeneration(DocumentManager $dm) + private function getClassesForProxyGeneration(DocumentManager $dm): array { return array_filter($dm->getMetadataFactory()->getAllMetadata(), static fn (ClassMetadata $metadata) => ! $metadata->isEmbeddedDocument && ! $metadata->isMappedSuperclass); } diff --git a/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php b/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php index 82b9498d..0c431c42 100644 --- a/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php +++ b/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php @@ -16,8 +16,7 @@ class CreateHydratorDirectoryPass implements CompilerPassInterface { - /** @return void */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (! $container->hasParameter('doctrine_mongodb.odm.hydrator_dir')) { return; diff --git a/DependencyInjection/Compiler/CreateProxyDirectoryPass.php b/DependencyInjection/Compiler/CreateProxyDirectoryPass.php index 5139534e..8cfd7a35 100644 --- a/DependencyInjection/Compiler/CreateProxyDirectoryPass.php +++ b/DependencyInjection/Compiler/CreateProxyDirectoryPass.php @@ -16,8 +16,7 @@ class CreateProxyDirectoryPass implements CompilerPassInterface { - /** @return void */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (! $container->hasParameter('doctrine_mongodb.odm.proxy_dir')) { return; diff --git a/DependencyInjection/Compiler/FixturesCompilerPass.php b/DependencyInjection/Compiler/FixturesCompilerPass.php index bacd82b0..33e1e55e 100644 --- a/DependencyInjection/Compiler/FixturesCompilerPass.php +++ b/DependencyInjection/Compiler/FixturesCompilerPass.php @@ -12,8 +12,7 @@ final class FixturesCompilerPass implements CompilerPassInterface { public const FIXTURE_TAG = 'doctrine.fixture.odm.mongodb'; - /** @return void */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { if (! $container->hasDefinition('doctrine_mongodb.odm.symfony.fixtures.loader')) { return; diff --git a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php index d72dcfae..9e3b2414 100644 --- a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php +++ b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php @@ -17,8 +17,7 @@ final class ServiceRepositoryCompilerPass implements CompilerPassInterface { public const REPOSITORY_SERVICE_TAG = 'doctrine_mongodb.odm.repository_service'; - /** @return void */ - public function process(ContainerBuilder $container) + public function process(ContainerBuilder $container): void { // when ODM is not enabled if (! $container->hasDefinition('doctrine_mongodb.odm.container_repository_factory')) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 3fd9c98b..0599c47e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -24,10 +24,8 @@ class Configuration implements ConfigurationInterface { /** * Generates the configuration tree builder. - * - * @return TreeBuilder */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('doctrine_mongodb'); $rootNode = $treeBuilder->getRootNode(); @@ -158,7 +156,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode): void ->end() ->beforeNormalization() // The content of the XML node is returned as the "value" key so we need to rename it - ->ifTrue(static function ($v) { + ->ifTrue(static function ($v): bool { return is_array($v) && isset($v['value']); }) ->then(static function ($v) { @@ -177,7 +175,7 @@ private function addDocumentManagersSection(ArrayNodeDefinition $rootNode): void ->prototype('variable') ->beforeNormalization() // Detect JSON object and array syntax (for XML) - ->ifTrue(static function ($v) { + ->ifTrue(static function ($v): bool { return is_string($v) && (preg_match('/\[.*\]/', $v) || preg_match('/\{.*\}/', $v)); }) // Decode objects to associative arrays for consistency with YAML @@ -277,7 +275,7 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode): void ->prototype('array') ->beforeNormalization() // Handle readPreferenceTag XML nodes - ->ifTrue(static function ($v) { + ->ifTrue(static function ($v): bool { return isset($v['readPreferenceTag']); }) ->then(static function ($v) { @@ -298,7 +296,7 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode): void ->ifNull()->thenUnset() ->end() ->validate() - ->ifTrue(static function ($v) { + ->ifTrue(static function ($v): bool { return ! is_string($v) && $v !== null; })->thenInvalid('The replicaSet option must be a string or null.') ->end() @@ -328,7 +326,7 @@ private function addConnectionsSection(ArrayNodeDefinition $rootNode): void ->integerNode('wTimeout')->info('Deprecated. Please use the "wTimeoutMS" option instead.')->end() ->end() ->validate() - ->ifTrue(static function ($v) { + ->ifTrue(static function ($v): bool { return count($v['readPreferenceTags']) === 0; }) ->then(static function ($v) { diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index 0224ee5d..7921dbf6 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -59,10 +59,8 @@ class DoctrineMongoDBExtension extends AbstractDoctrineExtension /** * Responds to the doctrine_mongodb configuration parameter. - * - * @return void */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { // Load DoctrineMongoDBBundle/Resources/config/mongodb.xml $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); @@ -135,7 +133,7 @@ public function load(array $configs, ContainerBuilder $container) $container->registerForAutoconfiguration(EventSubscriberInterface::class) ->addTag('doctrine_mongodb.odm.event_subscriber'); - $container->registerAttributeForAutoconfiguration(AsDocumentListener::class, static function (ChildDefinition $definition, AsDocumentListener $attribute) { + $container->registerAttributeForAutoconfiguration(AsDocumentListener::class, static function (ChildDefinition $definition, AsDocumentListener $attribute): void { $definition->addTag('doctrine_mongodb.odm.event_listener', [ 'event' => $attribute->event, 'method' => $attribute->method, diff --git a/Form/DoctrineMongoDBTypeGuesser.php b/Form/DoctrineMongoDBTypeGuesser.php index a57e01bd..4f69b16c 100644 --- a/Form/DoctrineMongoDBTypeGuesser.php +++ b/Form/DoctrineMongoDBTypeGuesser.php @@ -146,7 +146,7 @@ public function guessMaxLength(string $class, string $property) /** * {@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 97653387..fe708c39 100644 --- a/Form/Type/DocumentType.php +++ b/Form/Type/DocumentType.php @@ -30,8 +30,7 @@ public function getLoader(ObjectManager $manager, object $queryBuilder, string $ ); } - /** @return void */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { parent::configureOptions($resolver); From 3c68459da3137ff611744d5ebf8a6ea2219281ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Sat, 9 Dec 2023 18:32:29 +0100 Subject: [PATCH 2/2] Add Command::execute return type int --- CacheWarmer/HydratorCacheWarmer.php | 4 +- .../PersistentCollectionCacheWarmer.php | 4 +- CacheWarmer/ProxyCacheWarmer.php | 4 +- .../ClearMetadataCacheDoctrineODMCommand.php | 6 +-- Command/CreateSchemaDoctrineODMCommand.php | 6 +-- Command/DoctrineODMCommand.php | 9 +---- Command/DropSchemaDoctrineODMCommand.php | 6 +-- .../GenerateHydratorsDoctrineODMCommand.php | 6 +-- Command/GenerateProxiesDoctrineODMCommand.php | 6 +-- Command/InfoDoctrineODMCommand.php | 6 +-- .../LoadDataFixturesDoctrineODMCommand.php | 9 ++--- Command/QueryDoctrineODMCommand.php | 6 +-- Command/ShardDoctrineODMCommand.php | 6 +-- Command/UpdateSchemaDoctrineODMCommand.php | 6 +-- psalm-baseline.xml | 40 ------------------- 15 files changed, 29 insertions(+), 95 deletions(-) diff --git a/CacheWarmer/HydratorCacheWarmer.php b/CacheWarmer/HydratorCacheWarmer.php index cd391959..8348aaea 100644 --- a/CacheWarmer/HydratorCacheWarmer.php +++ b/CacheWarmer/HydratorCacheWarmer.php @@ -40,13 +40,13 @@ public function __construct(private ContainerInterface $container) * * @return false */ - public function isOptional() + public function isOptional(): bool { return false; } /** @return string[] */ - public function warmUp(string $cacheDir, ?string $buildDir = null) + public function warmUp(string $cacheDir, ?string $buildDir = null): array { // we need the directory no matter the hydrator cache generation strategy. $hydratorCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.hydrator_dir'); diff --git a/CacheWarmer/PersistentCollectionCacheWarmer.php b/CacheWarmer/PersistentCollectionCacheWarmer.php index fa3f2327..6d6d5824 100644 --- a/CacheWarmer/PersistentCollectionCacheWarmer.php +++ b/CacheWarmer/PersistentCollectionCacheWarmer.php @@ -41,13 +41,13 @@ public function __construct(private ContainerInterface $container) * * @return false */ - public function isOptional() + public function isOptional(): bool { return false; } /** @return string[] */ - public function warmUp(string $cacheDir, ?string $buildDir = null) + public function warmUp(string $cacheDir, ?string $buildDir = null): array { // we need the directory no matter the hydrator cache generation strategy. $collCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.persistent_collection_dir'); diff --git a/CacheWarmer/ProxyCacheWarmer.php b/CacheWarmer/ProxyCacheWarmer.php index c6eec363..e927f4d3 100644 --- a/CacheWarmer/ProxyCacheWarmer.php +++ b/CacheWarmer/ProxyCacheWarmer.php @@ -42,13 +42,13 @@ public function __construct(private ContainerInterface $container) * * @return false */ - public function isOptional() + public function isOptional(): bool { return false; } /** @return string[] */ - public function warmUp(string $cacheDir, ?string $buildDir = null) + public function warmUp(string $cacheDir, ?string $buildDir = null): array { // we need the directory no matter the proxy cache generation strategy. $proxyCacheDir = (string) $this->container->getParameter('doctrine_mongodb.odm.proxy_dir'); diff --git a/Command/ClearMetadataCacheDoctrineODMCommand.php b/Command/ClearMetadataCacheDoctrineODMCommand.php index 5067c566..be239a1a 100644 --- a/Command/ClearMetadataCacheDoctrineODMCommand.php +++ b/Command/ClearMetadataCacheDoctrineODMCommand.php @@ -14,8 +14,7 @@ */ class ClearMetadataCacheDoctrineODMCommand extends MetadataCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -35,8 +34,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/Command/CreateSchemaDoctrineODMCommand.php b/Command/CreateSchemaDoctrineODMCommand.php index 2a024916..9fc7fe20 100644 --- a/Command/CreateSchemaDoctrineODMCommand.php +++ b/Command/CreateSchemaDoctrineODMCommand.php @@ -15,8 +15,7 @@ */ class CreateSchemaDoctrineODMCommand extends CreateCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -35,8 +34,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/Command/DoctrineODMCommand.php b/Command/DoctrineODMCommand.php index 1f3b1cd5..4f2ee3d6 100644 --- a/Command/DoctrineODMCommand.php +++ b/Command/DoctrineODMCommand.php @@ -22,19 +22,14 @@ public function __construct(private ManagerRegistry $registry) } /** @param string $dmName */ - public static function setApplicationDocumentManager(Application $application, $dmName) + public static function setApplicationDocumentManager(Application $application, $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->registry; } diff --git a/Command/DropSchemaDoctrineODMCommand.php b/Command/DropSchemaDoctrineODMCommand.php index cd92b546..33a4bee9 100644 --- a/Command/DropSchemaDoctrineODMCommand.php +++ b/Command/DropSchemaDoctrineODMCommand.php @@ -15,8 +15,7 @@ */ class DropSchemaDoctrineODMCommand extends DropCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -35,8 +34,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/Command/GenerateHydratorsDoctrineODMCommand.php b/Command/GenerateHydratorsDoctrineODMCommand.php index dcb9e58f..6aee2a5f 100644 --- a/Command/GenerateHydratorsDoctrineODMCommand.php +++ b/Command/GenerateHydratorsDoctrineODMCommand.php @@ -14,8 +14,7 @@ */ class GenerateHydratorsDoctrineODMCommand extends GenerateHydratorsCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -34,8 +33,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/Command/GenerateProxiesDoctrineODMCommand.php b/Command/GenerateProxiesDoctrineODMCommand.php index b0678a5c..6400d724 100644 --- a/Command/GenerateProxiesDoctrineODMCommand.php +++ b/Command/GenerateProxiesDoctrineODMCommand.php @@ -14,8 +14,7 @@ */ class GenerateProxiesDoctrineODMCommand extends GenerateProxiesCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -34,8 +33,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/Command/InfoDoctrineODMCommand.php b/Command/InfoDoctrineODMCommand.php index 607dd2e5..1096a802 100644 --- a/Command/InfoDoctrineODMCommand.php +++ b/Command/InfoDoctrineODMCommand.php @@ -20,8 +20,7 @@ */ class InfoDoctrineODMCommand extends DoctrineODMCommand { - /** @return void */ - protected function configure() + protected function configure(): void { $this ->setName('doctrine:mongodb:mapping:info') @@ -40,8 +39,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $documentManagerName = $input->hasOption('dm') ? $input->getOption('dm') : $this->getManagerRegistry()->getDefaultManagerName(); diff --git a/Command/LoadDataFixturesDoctrineODMCommand.php b/Command/LoadDataFixturesDoctrineODMCommand.php index 83694e42..557c5719 100644 --- a/Command/LoadDataFixturesDoctrineODMCommand.php +++ b/Command/LoadDataFixturesDoctrineODMCommand.php @@ -32,14 +32,12 @@ public function __construct(?ManagerRegistry $registry = null, ?KernelInterface parent::__construct($registry); } - /** @return bool */ - public function isEnabled() + public function isEnabled(): bool { return parent::isEnabled() && class_exists(Loader::class); } - /** @return void */ - protected function configure() + protected function configure(): void { $this ->setName('doctrine:mongodb:fixtures:load') @@ -69,8 +67,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $dm = $this->getManagerRegistry()->getManager($input->getOption('dm')); $ui = new SymfonyStyle($input, $output); diff --git a/Command/QueryDoctrineODMCommand.php b/Command/QueryDoctrineODMCommand.php index 3b2f9cde..5c6e6381 100644 --- a/Command/QueryDoctrineODMCommand.php +++ b/Command/QueryDoctrineODMCommand.php @@ -14,8 +14,7 @@ */ class QueryDoctrineODMCommand extends QueryCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -24,8 +23,7 @@ protected function configure() ->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.'); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/Command/ShardDoctrineODMCommand.php b/Command/ShardDoctrineODMCommand.php index c13cf10d..33e70a1b 100644 --- a/Command/ShardDoctrineODMCommand.php +++ b/Command/ShardDoctrineODMCommand.php @@ -15,8 +15,7 @@ */ class ShardDoctrineODMCommand extends ShardCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -35,8 +34,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/Command/UpdateSchemaDoctrineODMCommand.php b/Command/UpdateSchemaDoctrineODMCommand.php index 870c9a5b..3895efc0 100644 --- a/Command/UpdateSchemaDoctrineODMCommand.php +++ b/Command/UpdateSchemaDoctrineODMCommand.php @@ -15,8 +15,7 @@ */ class UpdateSchemaDoctrineODMCommand extends UpdateCommand { - /** @return void */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -35,8 +34,7 @@ protected function configure() ); } - /** @return int */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { DoctrineODMCommand::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index dc12b4d3..bc24f184 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,50 +1,10 @@ - - - protected function execute(InputInterface $input, OutputInterface $output) - - - - - protected function execute(InputInterface $input, OutputInterface $output) - - - - - protected function execute(InputInterface $input, OutputInterface $output) - - - - - protected function execute(InputInterface $input, OutputInterface $output) - - - - - protected function execute(InputInterface $input, OutputInterface $output) - - ask - - - protected function execute(InputInterface $input, OutputInterface $output) - - - - - protected function execute(InputInterface $input, OutputInterface $output) - - - - - protected function execute(InputInterface $input, OutputInterface $output) - - arrayNode