From 43ef7db4023f9bb47826d32a7459f48b320a8545 Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Sun, 5 Mar 2023 14:24:15 +0100 Subject: [PATCH] Use PHP 7.4 syntax --- CacheWarmer/ProxyCacheWarmer.php | 4 +--- Command/InfoDoctrineODMCommand.php | 4 +--- DataCollector/CommandDataCollector.php | 4 +--- .../ServiceRepositoryCompilerPass.php | 4 +--- DependencyInjection/Configuration.php | 4 +--- .../AbstractMongoDBExtensionTest.php | 4 +--- Tests/FixtureIntegrationTest.php | 20 +++++-------------- .../ContainerRepositoryFactoryTest.php | 12 +++-------- 8 files changed, 14 insertions(+), 42 deletions(-) diff --git a/CacheWarmer/ProxyCacheWarmer.php b/CacheWarmer/ProxyCacheWarmer.php index dde971dd..6a3b8e5e 100644 --- a/CacheWarmer/ProxyCacheWarmer.php +++ b/CacheWarmer/ProxyCacheWarmer.php @@ -86,8 +86,6 @@ public function warmUp($cacheDir) /** @return ClassMetadata[] */ private function getClassesForProxyGeneration(DocumentManager $dm) { - return array_filter($dm->getMetadataFactory()->getAllMetadata(), static function (ClassMetadata $metadata) { - return ! $metadata->isEmbeddedDocument && ! $metadata->isMappedSuperclass; - }); + return array_filter($dm->getMetadataFactory()->getAllMetadata(), static fn (ClassMetadata $metadata) => ! $metadata->isEmbeddedDocument && ! $metadata->isMappedSuperclass); } } diff --git a/Command/InfoDoctrineODMCommand.php b/Command/InfoDoctrineODMCommand.php index 3914ea5a..2e184e26 100644 --- a/Command/InfoDoctrineODMCommand.php +++ b/Command/InfoDoctrineODMCommand.php @@ -43,9 +43,7 @@ protected function configure() /** @return int */ protected function execute(InputInterface $input, OutputInterface $output) { - $documentManagerName = $input->getOption('dm') ? - $input->getOption('dm') : - $this->getManagerRegistry()->getDefaultManagerName(); + $documentManagerName = $input->hasOption('dm') ? $input->getOption('dm') : $this->getManagerRegistry()->getDefaultManagerName(); $documentManager = $this->getManagerRegistry()->getManager($documentManagerName); assert($documentManager instanceof DocumentManager); diff --git a/DataCollector/CommandDataCollector.php b/DataCollector/CommandDataCollector.php index 145557ec..a3d02d2d 100644 --- a/DataCollector/CommandDataCollector.php +++ b/DataCollector/CommandDataCollector.php @@ -47,9 +47,7 @@ static function (Command $command): array { ), 'time' => array_reduce( $this->commandLogger->getAll(), - static function (int $total, Command $command): int { - return $total + $command->getDurationMicros(); - }, + static fn (int $total, Command $command): int => $total + $command->getDurationMicros(), 0 ), ]; diff --git a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php index c2cfd60a..d72dcfae 100644 --- a/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php +++ b/DependencyInjection/Compiler/ServiceRepositoryCompilerPass.php @@ -29,9 +29,7 @@ public function process(ContainerBuilder $container) $repoServiceIds = array_keys($container->findTaggedServiceIds(self::REPOSITORY_SERVICE_TAG)); - $repoReferences = array_map(static function ($id) { - return new Reference($id); - }, $repoServiceIds); + $repoReferences = array_map(static fn ($id) => new Reference($id), $repoServiceIds); $locatorDef->replaceArgument(0, ServiceLocatorTagPass::register($container, array_combine($repoServiceIds, $repoReferences))); } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 666aed80..d265145a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -389,9 +389,7 @@ private function addTypesSection(ArrayNodeDefinition $rootNode) ->prototype('array') ->beforeNormalization() ->ifString() - ->then(static function ($v) { - return ['class' => $v]; - }) + ->then(static fn ($v) => ['class' => $v]) ->end() ->children() ->scalarNode('class')->isRequired()->end() diff --git a/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php b/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php index d3891b30..a0d25bd9 100644 --- a/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php +++ b/Tests/DependencyInjection/AbstractMongoDBExtensionTest.php @@ -166,9 +166,7 @@ public function testLoadSimpleSingleConnection(): void $definition = $container->getDefinition('doctrine_mongodb.odm.default_configuration'); $methodCalls = $definition->getMethodCalls(); - $methodNames = array_map(static function ($call) { - return $call[0]; - }, $methodCalls); + $methodNames = array_map(static fn ($call) => $call[0], $methodCalls); $this->assertIsInt($pos = array_search('setDefaultDB', $methodNames)); $this->assertEquals('mydb', $methodCalls[$pos][1][0]); diff --git a/Tests/FixtureIntegrationTest.php b/Tests/FixtureIntegrationTest.php index c78db6fe..97d6e0ad 100644 --- a/Tests/FixtureIntegrationTest.php +++ b/Tests/FixtureIntegrationTest.php @@ -52,9 +52,7 @@ public function testFixturesLoader(): void $actualFixtures = $loader->getFixtures(); $this->assertCount(2, $actualFixtures); - $actualFixtureClasses = array_map(static function ($fixture) { - return get_class($fixture); - }, $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -85,9 +83,7 @@ public function testFixturesLoaderWhenFixtureHasDependencyThatIsNotYetLoaded(): $actualFixtures = $loader->getFixtures(); $this->assertCount(2, $actualFixtures); - $actualFixtureClasses = array_map(static function ($fixture) { - return get_class($fixture); - }, $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -143,9 +139,7 @@ public function testFixturesLoaderWithGroupsOptionViaInterface(): void $actualFixtures = $loader->getFixtures(['staging']); $this->assertCount(1, $actualFixtures); - $actualFixtureClasses = array_map(static function ($fixture) { - return get_class($fixture); - }, $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -234,9 +228,7 @@ public function testLoadFixturesViaGroupWithFulfilledDependency(): void $actualFixtures = $loader->getFixtures(['fulfilledDependencyGroup']); $this->assertCount(2, $actualFixtures); - $actualFixtureClasses = array_map(static function ($fixture) { - return get_class($fixture); - }, $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); $this->assertSame([ OtherFixtures::class, @@ -267,9 +259,7 @@ public function testLoadFixturesByShortName(): void $actualFixtures = $loader->getFixtures(['OtherFixtures']); $this->assertCount(1, $actualFixtures); - $actualFixtureClasses = array_map(static function ($fixture) { - return get_class($fixture); - }, $actualFixtures); + $actualFixtureClasses = array_map(static fn ($fixture) => get_class($fixture), $actualFixtures); $this->assertSame([ OtherFixtures::class, diff --git a/Tests/Repository/ContainerRepositoryFactoryTest.php b/Tests/Repository/ContainerRepositoryFactoryTest.php index 7d8c1482..74ec3405 100644 --- a/Tests/Repository/ContainerRepositoryFactoryTest.php +++ b/Tests/Repository/ContainerRepositoryFactoryTest.php @@ -122,14 +122,10 @@ private function createContainer(array $services) $container = $this->getMockBuilder(ContainerInterface::class)->getMock(); $container ->method('has') - ->willReturnCallback(static function ($id) use ($services) { - return isset($services[$id]); - }); + ->willReturnCallback(static fn ($id) => isset($services[$id])); $container ->method('get') - ->willReturnCallback(static function ($id) use ($services) { - return $services[$id]; - }); + ->willReturnCallback(static fn ($id) => $services[$id]); return $container; } @@ -148,9 +144,7 @@ private function createDocumentManager(array $documentRepositoryClasses) $dm = $this->getMockBuilder(DocumentManager::class)->disableOriginalConstructor()->getMock(); $dm ->method('getClassMetadata') - ->willReturnCallback(static function ($class) use ($classMetadatas) { - return $classMetadatas[$class]; - }); + ->willReturnCallback(static fn ($class) => $classMetadatas[$class]); $evm = $this->createMock(EventManager::class);