Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add return types required by extending Symfony classes #797

Merged
merged 2 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

Check warning on line 17 in Command/ClearMetadataCacheDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/ClearMetadataCacheDoctrineODMCommand.php#L17

Added line #L17 was not covered by tests
{
parent::configure();

Expand All @@ -35,8 +34,7 @@
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int

Check warning on line 37 in Command/ClearMetadataCacheDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/ClearMetadataCacheDoctrineODMCommand.php#L37

Added line #L37 was not covered by tests
{
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

Check warning on line 18 in Command/CreateSchemaDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/CreateSchemaDoctrineODMCommand.php#L18

Added line #L18 was not covered by tests
{
parent::configure();

Expand All @@ -35,8 +34,7 @@
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int

Check warning on line 37 in Command/CreateSchemaDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/CreateSchemaDoctrineODMCommand.php#L37

Added line #L37 was not covered by tests
{
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 @@
}

/** @param string $dmName */
public static function setApplicationDocumentManager(Application $application, $dmName)
public static function setApplicationDocumentManager(Application $application, $dmName): void

Check warning on line 25 in Command/DoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/DoctrineODMCommand.php#L25

Added line #L25 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public static function setApplicationDocumentManager(Application $application, $dmName): void
public static function setApplicationDocumentManager(Application $application, string $dmName): void

I'll check these native types in another PR as I guess we have some more we can add, so feel free to ignore this comment in this PR.

{
$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

Check warning on line 18 in Command/DropSchemaDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/DropSchemaDoctrineODMCommand.php#L18

Added line #L18 was not covered by tests
{
parent::configure();

Expand All @@ -35,8 +34,7 @@
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int

Check warning on line 37 in Command/DropSchemaDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/DropSchemaDoctrineODMCommand.php#L37

Added line #L37 was not covered by tests
{
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

Check warning on line 17 in Command/GenerateHydratorsDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/GenerateHydratorsDoctrineODMCommand.php#L17

Added line #L17 was not covered by tests
{
parent::configure();

Expand All @@ -34,8 +33,7 @@
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int

Check warning on line 36 in Command/GenerateHydratorsDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/GenerateHydratorsDoctrineODMCommand.php#L36

Added line #L36 was not covered by tests
{
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

Check warning on line 17 in Command/GenerateProxiesDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/GenerateProxiesDoctrineODMCommand.php#L17

Added line #L17 was not covered by tests
{
parent::configure();

Expand All @@ -34,8 +33,7 @@
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int

Check warning on line 36 in Command/GenerateProxiesDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/GenerateProxiesDoctrineODMCommand.php#L36

Added line #L36 was not covered by tests
{
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

Check warning on line 17 in Command/QueryDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/QueryDoctrineODMCommand.php#L17

Added line #L17 was not covered by tests
{
parent::configure();

Expand All @@ -24,8 +23,7 @@
->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

Check warning on line 26 in Command/QueryDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/QueryDoctrineODMCommand.php#L26

Added line #L26 was not covered by tests
{
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

Check warning on line 18 in Command/ShardDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/ShardDoctrineODMCommand.php#L18

Added line #L18 was not covered by tests
{
parent::configure();

Expand All @@ -35,8 +34,7 @@
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int

Check warning on line 37 in Command/ShardDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/ShardDoctrineODMCommand.php#L37

Added line #L37 was not covered by tests
{
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

Check warning on line 18 in Command/UpdateSchemaDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/UpdateSchemaDoctrineODMCommand.php#L18

Added line #L18 was not covered by tests
{
parent::configure();

Expand All @@ -35,8 +34,7 @@
);
}

/** @return int */
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int

Check warning on line 37 in Command/UpdateSchemaDoctrineODMCommand.php

View check run for this annotation

Codecov / codecov/patch

Command/UpdateSchemaDoctrineODMCommand.php#L37

Added line #L37 was not covered by tests
{
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