Skip to content

Commit 28543e9

Browse files
minor #51146 More short closures (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- More short closures | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- cf173a3321 More short closures
2 parents 3d02946 + e1facb5 commit 28543e9

File tree

7 files changed

+37
-47
lines changed

7 files changed

+37
-47
lines changed

Command/ConfigDebugCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class ConfigDebugCommand extends AbstractConfigCommand
4141
{
4242
protected function configure(): void
4343
{
44-
$commentedHelpFormats = array_map(static fn (string $format): string => sprintf('<comment>%s</comment>', $format), $this->getAvailableFormatOptions());
44+
$commentedHelpFormats = array_map(fn ($format) => sprintf('<comment>%s</comment>', $format), $this->getAvailableFormatOptions());
4545
$helpFormats = implode('", "', $commentedHelpFormats);
4646

4747
$this

Command/ConfigDumpReferenceCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ConfigDumpReferenceCommand extends AbstractConfigCommand
3939
{
4040
protected function configure(): void
4141
{
42-
$commentedHelpFormats = array_map(static fn (string $format): string => sprintf('<comment>%s</comment>', $format), $this->getAvailableFormatOptions());
42+
$commentedHelpFormats = array_map(fn ($format) => sprintf('<comment>%s</comment>', $format), $this->getAvailableFormatOptions());
4343
$helpFormats = implode('", "', $commentedHelpFormats);
4444

4545
$this

Command/SecretsListCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7575
$rows = [];
7676

7777
$dump = new Dumper($output);
78-
$dump = static fn (?string $v) => null === $v ? '******' : $dump($v);
78+
$dump = fn ($v) => null === $v ? '******' : $dump($v);
7979

8080
foreach ($secrets as $name => $value) {
8181
$rows[$name] = [$name, $dump($value)];

DependencyInjection/Configuration.php

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function getConfigTreeBuilder(): TreeBuilder
7474

7575
$rootNode
7676
->beforeNormalization()
77-
->ifTrue(function ($v) { return !isset($v['assets']) && isset($v['templating']) && class_exists(Package::class); })
77+
->ifTrue(fn ($v) => !isset($v['assets']) && isset($v['templating']) && class_exists(Package::class))
7878
->then(function ($v) {
7979
$v['assets'] = [];
8080

@@ -119,15 +119,15 @@ public function getConfigTreeBuilder(): TreeBuilder
119119
->prototype('scalar')->end()
120120
->end()
121121
->arrayNode('trusted_hosts')
122-
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
122+
->beforeNormalization()->ifString()->then(fn ($v) => [$v])->end()
123123
->prototype('scalar')->end()
124124
->end()
125125
->scalarNode('trusted_proxies')->end()
126126
->arrayNode('trusted_headers')
127127
->fixXmlConfig('trusted_header')
128128
->performNoDeepMerging()
129129
->defaultValue(['x-forwarded-for', 'x-forwarded-port', 'x-forwarded-proto'])
130-
->beforeNormalization()->ifString()->then(function ($v) { return $v ? array_map('trim', explode(',', $v)) : []; })->end()
130+
->beforeNormalization()->ifString()->then(fn ($v) => $v ? array_map('trim', explode(',', $v)) : [])->end()
131131
->enumPrototype()
132132
->values([
133133
'forwarded',
@@ -149,7 +149,7 @@ public function getConfigTreeBuilder(): TreeBuilder
149149
return ContainerBuilder::willBeAvailable($package, $class, $parentPackages);
150150
};
151151

152-
$enableIfStandalone = static fn (string $package, string $class) => !class_exists(FullStack::class) && $willBeAvailable($package, $class) ? 'canBeDisabled' : 'canBeEnabled';
152+
$enableIfStandalone = fn (string $package, string $class) => !class_exists(FullStack::class) && $willBeAvailable($package, $class) ? 'canBeDisabled' : 'canBeEnabled';
153153

154154
$this->addCsrfSection($rootNode);
155155
$this->addFormSection($rootNode, $enableIfStandalone);
@@ -416,12 +416,12 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
416416
->arrayNode('supports')
417417
->beforeNormalization()
418418
->ifString()
419-
->then(function ($v) { return [$v]; })
419+
->then(fn ($v) => [$v])
420420
->end()
421421
->prototype('scalar')
422422
->cannotBeEmpty()
423423
->validate()
424-
->ifTrue(function ($v) { return !class_exists($v) && !interface_exists($v, false); })
424+
->ifTrue(fn ($v) => !class_exists($v) && !interface_exists($v, false))
425425
->thenInvalid('The supported class or interface "%s" does not exist.')
426426
->end()
427427
->end()
@@ -550,7 +550,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
550550
->arrayNode('from')
551551
->beforeNormalization()
552552
->ifString()
553-
->then(function ($v) { return [$v]; })
553+
->then(fn ($v) => [$v])
554554
->end()
555555
->requiresAtLeastOneElement()
556556
->prototype('scalar')
@@ -560,7 +560,7 @@ private function addWorkflowSection(ArrayNodeDefinition $rootNode): void
560560
->arrayNode('to')
561561
->beforeNormalization()
562562
->ifString()
563-
->then(function ($v) { return [$v]; })
563+
->then(fn ($v) => [$v])
564564
->end()
565565
->requiresAtLeastOneElement()
566566
->prototype('scalar')
@@ -782,8 +782,8 @@ private function addAssetsSection(ArrayNodeDefinition $rootNode, callable $enabl
782782
->scalarNode('version_strategy')->defaultNull()->end()
783783
->scalarNode('version')
784784
->beforeNormalization()
785-
->ifTrue(function ($v) { return '' === $v; })
786-
->then(function ($v) { return; })
785+
->ifTrue(fn ($v) => '' === $v)
786+
->then(fn () => null)
787787
->end()
788788
->end()
789789
->scalarNode('version_format')->defaultNull()->end()
@@ -932,7 +932,7 @@ private function addTranslatorSection(ArrayNodeDefinition $rootNode, callable $e
932932
->children()
933933
->arrayNode('fallbacks')
934934
->info('Defaults to the value of "default_locale".')
935-
->beforeNormalization()->ifString()->then(function ($v) { return [$v]; })->end()
935+
->beforeNormalization()->ifString()->then(fn ($v) => [$v])->end()
936936
->prototype('scalar')->end()
937937
->defaultValue([])
938938
->end()
@@ -1197,7 +1197,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBe
11971197
->prototype('array')
11981198
->fixXmlConfig('adapter')
11991199
->beforeNormalization()
1200-
->ifTrue(function ($v) { return isset($v['provider']) && \is_array($v['adapters'] ?? $v['adapter'] ?? null) && 1 < \count($v['adapters'] ?? $v['adapter']); })
1200+
->ifTrue(fn ($v) => isset($v['provider']) && \is_array($v['adapters'] ?? $v['adapter'] ?? null) && 1 < \count($v['adapters'] ?? $v['adapter']))
12011201
->thenInvalid('Pool cannot have a "provider" while more than one adapter is defined')
12021202
->end()
12031203
->children()
@@ -1245,7 +1245,7 @@ private function addCacheSection(ArrayNodeDefinition $rootNode, callable $willBe
12451245
->end()
12461246
->end()
12471247
->validate()
1248-
->ifTrue(function ($v) { return isset($v['cache.app']) || isset($v['cache.system']); })
1248+
->ifTrue(fn ($v) => isset($v['cache.app']) || isset($v['cache.system']))
12491249
->thenInvalid('"cache.app" and "cache.system" are reserved names')
12501250
->end()
12511251
->end()
@@ -1386,7 +1386,7 @@ private function addLockSection(ArrayNodeDefinition $rootNode, callable $enableI
13861386
->end()
13871387
->addDefaultsIfNotSet()
13881388
->validate()
1389-
->ifTrue(static fn (array $config) => $config['enabled'] && !$config['resources'])
1389+
->ifTrue(fn ($config) => $config['enabled'] && !$config['resources'])
13901390
->thenInvalid('At least one resource must be defined.')
13911391
->end()
13921392
->fixXmlConfig('resource')
@@ -1501,12 +1501,12 @@ private function addMessengerSection(ArrayNodeDefinition $rootNode, callable $en
15011501
->fixXmlConfig('transport')
15021502
->fixXmlConfig('bus', 'buses')
15031503
->validate()
1504-
->ifTrue(function ($v) { return isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus']; })
1504+
->ifTrue(fn ($v) => isset($v['buses']) && \count($v['buses']) > 1 && null === $v['default_bus'])
15051505
->thenInvalid('You must specify the "default_bus" if you define more than one bus.')
15061506
->end()
15071507
->validate()
1508-
->ifTrue(static function ($v): bool { return isset($v['buses']) && null !== $v['default_bus'] && !isset($v['buses'][$v['default_bus']]); })
1509-
->then(static function (array $v): void { throw new InvalidConfigurationException(sprintf('The specified default bus "%s" is not configured. Available buses are "%s".', $v['default_bus'], implode('", "', array_keys($v['buses'])))); })
1508+
->ifTrue(fn ($v) => isset($v['buses']) && null !== $v['default_bus'] && !isset($v['buses'][$v['default_bus']]))
1509+
->then(fn ($v) => throw new InvalidConfigurationException(sprintf('The specified default bus "%s" is not configured. Available buses are "%s".', $v['default_bus'], implode('", "', array_keys($v['buses'])))))
15101510
->end()
15111511
->children()
15121512
->arrayNode('routing')
@@ -1633,7 +1633,7 @@ function ($a) {
16331633
->info('Reset container services after each message.')
16341634
->setDeprecated('symfony/framework-bundle', '6.1', 'Option "%node%" at "%path%" is deprecated. It does nothing and will be removed in version 7.0.')
16351635
->validate()
1636-
->ifTrue(static fn ($v) => true !== $v)
1636+
->ifTrue(fn ($v) => true !== $v)
16371637
->thenInvalid('The "framework.messenger.reset_on_message" configuration option can be set to "true" only. To prevent services resetting after each message you can set the "--no-reset" option in "messenger:consume" command.')
16381638
->end()
16391639
->end()
@@ -1652,22 +1652,12 @@ function ($a) {
16521652
->children()
16531653
->arrayNode('default_middleware')
16541654
->beforeNormalization()
1655-
->ifTrue(function ($defaultMiddleware) { return \is_string($defaultMiddleware) || \is_bool($defaultMiddleware); })
1656-
->then(function ($defaultMiddleware): array {
1657-
if (\is_string($defaultMiddleware) && 'allow_no_handlers' === $defaultMiddleware) {
1658-
return [
1659-
'enabled' => true,
1660-
'allow_no_handlers' => true,
1661-
'allow_no_senders' => true,
1662-
];
1663-
}
1664-
1665-
return [
1666-
'enabled' => $defaultMiddleware,
1667-
'allow_no_handlers' => false,
1668-
'allow_no_senders' => true,
1669-
];
1670-
})
1655+
->ifTrue(fn ($v) => \is_string($v) || \is_bool($v))
1656+
->then(fn ($v) => [
1657+
'enabled' => 'allow_no_handlers' === $v ? true : $v,
1658+
'allow_no_handlers' => 'allow_no_handlers' === $v,
1659+
'allow_no_senders' => true,
1660+
])
16711661
->end()
16721662
->canBeDisabled()
16731663
->children()
@@ -1678,8 +1668,8 @@ function ($a) {
16781668
->arrayNode('middleware')
16791669
->performNoDeepMerging()
16801670
->beforeNormalization()
1681-
->ifTrue(function ($v) { return \is_string($v) || (\is_array($v) && !\is_int(key($v))); })
1682-
->then(function ($v) { return [$v]; })
1671+
->ifTrue(fn ($v) => \is_string($v) || (\is_array($v) && !\is_int(key($v))))
1672+
->then(fn ($v) => [$v])
16831673
->end()
16841674
->defaultValue([])
16851675
->arrayPrototype()
@@ -1894,11 +1884,11 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode, callable $e
18941884
})
18951885
->end()
18961886
->validate()
1897-
->ifTrue(function ($v) { return !isset($v['scope']) && !isset($v['base_uri']); })
1887+
->ifTrue(fn ($v) => !isset($v['scope']) && !isset($v['base_uri']))
18981888
->thenInvalid('Either "scope" or "base_uri" should be defined.')
18991889
->end()
19001890
->validate()
1901-
->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); })
1891+
->ifTrue(fn ($v) => !empty($v['query']) && !isset($v['base_uri']))
19021892
->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
19031893
->end()
19041894
->children()
@@ -2184,7 +2174,7 @@ private function addNotifierSection(ArrayNodeDefinition $rootNode, callable $ena
21842174
->arrayNode('channel_policy')
21852175
->useAttributeAsKey('name')
21862176
->prototype('array')
2187-
->beforeNormalization()->ifString()->then(function (string $v) { return [$v]; })->end()
2177+
->beforeNormalization()->ifString()->then(fn ($v) => [$v])->end()
21882178
->prototype('scalar')->end()
21892179
->end()
21902180
->end()
@@ -2456,7 +2446,7 @@ private function addHtmlSanitizerSection(ArrayNodeDefinition $rootNode, callable
24562446
->info('Allows only a given list of hosts to be used in links href attributes.')
24572447
->defaultValue(null)
24582448
->validate()
2459-
->ifTrue(function ($v) { return !\is_array($v) && null !== $v; })
2449+
->ifTrue(fn ($v) => !\is_array($v) && null !== $v)
24602450
->thenInvalid('The "allowed_link_hosts" parameter must be an array or null')
24612451
->end()
24622452
->end()
@@ -2472,7 +2462,7 @@ private function addHtmlSanitizerSection(ArrayNodeDefinition $rootNode, callable
24722462
->info('Allows only a given list of hosts to be used in media source attributes (img, audio, video, ...).')
24732463
->defaultValue(null)
24742464
->validate()
2475-
->ifTrue(function ($v) { return !\is_array($v) && null !== $v; })
2465+
->ifTrue(fn ($v) => !\is_array($v) && null !== $v)
24762466
->thenInvalid('The "allowed_media_hosts" parameter must be an array or null')
24772467
->end()
24782468
->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
15271527
'resource_files' => $files,
15281528
'scanned_directories' => $scannedDirectories = array_merge($dirs, $nonExistingDirs),
15291529
'cache_vary' => [
1530-
'scanned_directories' => array_map(static fn (string $dir): string => str_starts_with($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir, $scannedDirectories),
1530+
'scanned_directories' => array_map(fn ($dir) => str_starts_with($dir, $projectDir.'/') ? substr($dir, 1 + \strlen($projectDir)) : $dir, $scannedDirectories),
15311531
],
15321532
]
15331533
);

Tests/DependencyInjection/Compiler/UnusedTagsPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testMissingKnownTags()
4444
private function getKnownTags(): array
4545
{
4646
$tags = \Closure::bind(
47-
static fn () => UnusedTagsPass::KNOWN_TAGS,
47+
fn () => UnusedTagsPass::KNOWN_TAGS,
4848
null,
4949
UnusedTagsPass::class
5050
)();

Tests/DependencyInjection/FrameworkExtensionTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ public function testMessengerServicesRemovedWhenDisabled()
776776
$container = $this->createContainerFromFile('messenger_disabled');
777777
$messengerDefinitions = array_filter(
778778
$container->getDefinitions(),
779-
static fn ($name) => str_starts_with($name, 'messenger.'),
779+
fn ($name) => str_starts_with($name, 'messenger.'),
780780
\ARRAY_FILTER_USE_KEY
781781
);
782782

0 commit comments

Comments
 (0)