Skip to content

Commit

Permalink
Add return types required by extending Symfony classes (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Dec 9, 2023
1 parent 9fcfc1b commit c3cf6ac
Show file tree
Hide file tree
Showing 23 changed files with 44 additions and 119 deletions.
4 changes: 2 additions & 2 deletions CacheWarmer/HydratorCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions CacheWarmer/PersistentCollectionCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 3 additions & 3 deletions CacheWarmer/ProxyCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 2 additions & 4 deletions Command/ClearMetadataCacheDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
*/
class ClearMetadataCacheDoctrineODMCommand extends MetadataCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
6 changes: 2 additions & 4 deletions Command/CreateSchemaDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
class CreateSchemaDoctrineODMCommand extends CreateCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
9 changes: 2 additions & 7 deletions Command/DoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 2 additions & 4 deletions Command/DropSchemaDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
class DropSchemaDoctrineODMCommand extends DropCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
6 changes: 2 additions & 4 deletions Command/GenerateHydratorsDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
*/
class GenerateHydratorsDoctrineODMCommand extends GenerateHydratorsCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
6 changes: 2 additions & 4 deletions Command/GenerateProxiesDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
*/
class GenerateProxiesDoctrineODMCommand extends GenerateProxiesCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
6 changes: 2 additions & 4 deletions Command/InfoDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
*/
class InfoDoctrineODMCommand extends DoctrineODMCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
$this
->setName('doctrine:mongodb:mapping:info')
Expand All @@ -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();

Expand Down
9 changes: 3 additions & 6 deletions Command/LoadDataFixturesDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions Command/QueryDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
*/
class QueryDoctrineODMCommand extends QueryCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
6 changes: 2 additions & 4 deletions Command/ShardDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
class ShardDoctrineODMCommand extends ShardCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
6 changes: 2 additions & 4 deletions Command/UpdateSchemaDoctrineODMCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
class UpdateSchemaDoctrineODMCommand extends UpdateCommand
{
/** @return void */
protected function configure()
protected function configure(): void
{
parent::configure();

Expand All @@ -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'));

Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/Compiler/CreateHydratorDirectoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/Compiler/CreateProxyDirectoryPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions DependencyInjection/Compiler/FixturesCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down
14 changes: 6 additions & 8 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit c3cf6ac

Please sign in to comment.