Skip to content

Commit 6bd00c0

Browse files
minor #48793 Leverage arrow function syntax for closure (tigitz)
This PR was merged into the 6.3 branch. Discussion ---------- Leverage arrow function syntax for closure | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | Fix #47658 <!-- prefix each issue number with "Fix #", no need to create an issue if none exists, explain below instead --> | License | MIT | Doc PR | <!-- required for new features --> Rationale in the RFC [here](https://wiki.php.net/rfc/arrow_functions_v2#introduction) It's also notable that using arrow function syntax rather than the classic one has been enforced in the past by symfony core member: symfony/symfony#48069 (comment) So this PR would be consistent. Commits ------- f5802d3a2a Leverage arrow function syntax for closure
2 parents 1a12d15 + 7a12b11 commit 6bd00c0

File tree

14 files changed

+32
-52
lines changed

14 files changed

+32
-52
lines changed

Command/DebugFirewallCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,9 @@ private function displayAuthenticators(string $name, SymfonyStyle $io): void
216216
$io->table(
217217
['Classname'],
218218
array_map(
219-
static function ($authenticator) {
220-
return [
221-
$authenticator::class,
222-
];
223-
},
219+
static fn ($authenticator) => [
220+
$authenticator::class,
221+
],
224222
$authenticators
225223
)
226224
);

DependencyInjection/Compiler/SortFirewallListenersPass.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ private function sortFirewallContextListeners(Definition $definition, ContainerB
4545
$prioritiesByServiceId = $this->getListenerPriorities($listenerIteratorArgument, $container);
4646

4747
$listeners = $listenerIteratorArgument->getValues();
48-
usort($listeners, function (Reference $a, Reference $b) use ($prioritiesByServiceId) {
49-
return $prioritiesByServiceId[(string) $b] <=> $prioritiesByServiceId[(string) $a];
50-
});
48+
usort($listeners, fn (Reference $a, Reference $b) => $prioritiesByServiceId[(string) $b] <=> $prioritiesByServiceId[(string) $a]);
5149

5250
$listenerIteratorArgument->setValues(array_values($listeners));
5351
}

DependencyInjection/MainConfiguration.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ public function getConfigTreeBuilder(): TreeBuilder
7878
->booleanNode('allow_if_equal_granted_denied')->defaultTrue()->end()
7979
->end()
8080
->validate()
81-
->ifTrue(function ($v) { return isset($v['strategy'], $v['service']); })
81+
->ifTrue(fn ($v) => isset($v['strategy'], $v['service']))
8282
->thenInvalid('"strategy" and "service" cannot be used together.')
8383
->end()
8484
->validate()
85-
->ifTrue(function ($v) { return isset($v['strategy'], $v['strategy_service']); })
85+
->ifTrue(fn ($v) => isset($v['strategy'], $v['strategy_service']))
8686
->thenInvalid('"strategy" and "strategy_service" cannot be used together.')
8787
->end()
8888
->validate()
89-
->ifTrue(function ($v) { return isset($v['service'], $v['strategy_service']); })
89+
->ifTrue(fn ($v) => isset($v['service'], $v['strategy_service']))
9090
->thenInvalid('"service" and "strategy_service" cannot be used together.')
9191
->end()
9292
->end()
@@ -111,10 +111,10 @@ private function addRoleHierarchySection(ArrayNodeDefinition $rootNode)
111111
->useAttributeAsKey('id')
112112
->prototype('array')
113113
->performNoDeepMerging()
114-
->beforeNormalization()->ifString()->then(function ($v) { return ['value' => $v]; })->end()
114+
->beforeNormalization()->ifString()->then(fn ($v) => ['value' => $v])->end()
115115
->beforeNormalization()
116-
->ifTrue(function ($v) { return \is_array($v) && isset($v['value']); })
117-
->then(function ($v) { return preg_split('/\s*,\s*/', $v['value']); })
116+
->ifTrue(fn ($v) => \is_array($v) && isset($v['value']))
117+
->then(fn ($v) => preg_split('/\s*,\s*/', $v['value']))
118118
->end()
119119
->prototype('scalar')->end()
120120
->end()
@@ -324,9 +324,7 @@ private function addFirewallsSection(ArrayNodeDefinition $rootNode, array $facto
324324
$firewallNodeBuilder
325325
->end()
326326
->validate()
327-
->ifTrue(function ($v) {
328-
return true === $v['security'] && isset($v['pattern']) && !isset($v['request_matcher']);
329-
})
327+
->ifTrue(fn ($v) => true === $v['security'] && isset($v['pattern']) && !isset($v['request_matcher']))
330328
->then(function ($firewall) use ($abstractFactoryKeys) {
331329
foreach ($abstractFactoryKeys as $k) {
332330
if (!isset($firewall[$k]['check_path'])) {
@@ -375,7 +373,7 @@ private function addProvidersSection(ArrayNodeDefinition $rootNode)
375373
->arrayNode('providers')
376374
->beforeNormalization()
377375
->ifString()
378-
->then(function ($v) { return preg_split('/\s*,\s*/', $v); })
376+
->then(fn ($v) => preg_split('/\s*,\s*/', $v))
379377
->end()
380378
->prototype('scalar')->end()
381379
->end()
@@ -393,11 +391,11 @@ private function addProvidersSection(ArrayNodeDefinition $rootNode)
393391

394392
$providerNodeBuilder
395393
->validate()
396-
->ifTrue(function ($v) { return \count($v) > 1; })
394+
->ifTrue(fn ($v) => \count($v) > 1)
397395
->thenInvalid('You cannot set multiple provider types for the same provider')
398396
->end()
399397
->validate()
400-
->ifTrue(function ($v) { return 0 === \count($v); })
398+
->ifTrue(fn ($v) => 0 === \count($v))
401399
->thenInvalid('You must set a provider definition for the provider.')
402400
->end()
403401
;

DependencyInjection/Security/Factory/AccessTokenFactory.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function addConfiguration(NodeDefinition $node): void
4646
->fixXmlConfig('token_extractors')
4747
->beforeNormalization()
4848
->ifString()
49-
->then(static function (string $v): array { return [$v]; })
49+
->then(static fn (string $v): array => [$v])
5050
->end()
5151
->cannotBeEmpty()
5252
->defaultValue([
@@ -97,17 +97,15 @@ private function createExtractor(ContainerBuilder $container, string $firewallNa
9797
'request_body' => 'security.access_token_extractor.request_body',
9898
'header' => 'security.access_token_extractor.header',
9999
];
100-
$extractors = array_map(static function (string $extractor) use ($aliases): string {
101-
return $aliases[$extractor] ?? $extractor;
102-
}, $extractors);
100+
$extractors = array_map(static fn (string $extractor): string => $aliases[$extractor] ?? $extractor, $extractors);
103101

104102
if (1 === \count($extractors)) {
105103
return current($extractors);
106104
}
107105
$extractorId = sprintf('security.authenticator.access_token.chain_extractor.%s', $firewallName);
108106
$container
109107
->setDefinition($extractorId, new ChildDefinition('security.authenticator.access_token.chain_extractor'))
110-
->replaceArgument(0, array_map(function (string $extractorId): Reference {return new Reference($extractorId); }, $extractors))
108+
->replaceArgument(0, array_map(fn (string $extractorId): Reference => new Reference($extractorId), $extractors))
111109
;
112110

113111
return $extractorId;

DependencyInjection/Security/Factory/CustomAuthenticatorFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function addConfiguration(NodeDefinition $builder)
4747
$factoryRootNode
4848
->fixXmlConfig('custom_authenticator')
4949
->validate()
50-
->ifTrue(function ($v) { return isset($v['custom_authenticators']) && empty($v['custom_authenticators']); })
50+
->ifTrue(fn ($v) => isset($v['custom_authenticators']) && empty($v['custom_authenticators']))
5151
->then(function ($v) {
5252
unset($v['custom_authenticators']);
5353

DependencyInjection/Security/Factory/RememberMeFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function addConfiguration(NodeDefinition $node)
148148
->scalarNode('service')->end()
149149
->arrayNode('user_providers')
150150
->beforeNormalization()
151-
->ifString()->then(function ($v) { return [$v]; })
151+
->ifString()->then(fn ($v) => [$v])
152152
->end()
153153
->prototype('scalar')->end()
154154
->end()
@@ -162,7 +162,7 @@ public function addConfiguration(NodeDefinition $node)
162162
->end()
163163
->arrayNode('token_provider')
164164
->beforeNormalization()
165-
->ifString()->then(function ($v) { return ['service' => $v]; })
165+
->ifString()->then(fn ($v) => ['service' => $v])
166166
->end()
167167
->children()
168168
->scalarNode('service')->info('The service ID of a custom rememberme token provider.')->end()

DependencyInjection/Security/UserProvider/InMemoryFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function addConfiguration(NodeDefinition $node)
5454
->children()
5555
->scalarNode('password')->defaultNull()->end()
5656
->arrayNode('roles')
57-
->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
57+
->beforeNormalization()->ifString()->then(fn ($v) => preg_split('/\s*,\s*/', $v))->end()
5858
->prototype('scalar')->end()
5959
->end()
6060
->end()

DependencyInjection/Security/UserProvider/LdapFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function addConfiguration(NodeDefinition $node)
5959
->prototype('scalar')->end()
6060
->end()
6161
->arrayNode('default_roles')
62-
->beforeNormalization()->ifString()->then(function ($v) { return preg_split('/\s*,\s*/', $v); })->end()
62+
->beforeNormalization()->ifString()->then(fn ($v) => preg_split('/\s*,\s*/', $v))->end()
6363
->requiresAtLeastOneElement()
6464
->prototype('scalar')->end()
6565
->end()

DependencyInjection/SecurityExtension.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,7 @@ private function createFirewall(ContainerBuilder $container, string $id, array $
501501
$configuredEntryPoint = $defaultEntryPoint;
502502

503503
// authenticator manager
504-
$authenticators = array_map(function ($id) {
505-
return new Reference($id);
506-
}, $firewallAuthenticationProviders);
504+
$authenticators = array_map(fn ($id) => new Reference($id), $firewallAuthenticationProviders);
507505
$container
508506
->setDefinition($managerId = 'security.authenticator.manager.'.$id, new ChildDefinition('security.authenticator.manager'))
509507
->replaceArgument(0, $authenticators)
@@ -1027,9 +1025,7 @@ public function getConfiguration(array $config, ContainerBuilder $container): ?C
10271025

10281026
private function isValidIps(string|array $ips): bool
10291027
{
1030-
$ipsList = array_reduce((array) $ips, static function (array $ips, string $ip) {
1031-
return array_merge($ips, preg_split('/\s*,\s*/', $ip));
1032-
}, []);
1028+
$ipsList = array_reduce((array) $ips, static fn (array $ips, string $ip) => array_merge($ips, preg_split('/\s*,\s*/', $ip)), []);
10331029

10341030
if (!$ipsList) {
10351031
return false;
@@ -1081,9 +1077,7 @@ private function getSortedFactories(): array
10811077
$factories[] = array_merge($factory, [$i]);
10821078
}
10831079

1084-
usort($factories, function ($a, $b) {
1085-
return $b[0] <=> $a[0] ?: $a[2] <=> $b[2];
1086-
});
1080+
usort($factories, fn ($a, $b) => $b[0] <=> $a[0] ?: $a[2] <=> $b[2]);
10871081

10881082
$this->sortedFactories = array_column($factories, 1);
10891083
}

Tests/DataCollector/SecurityDataCollectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ public function testCollectDecisionLog(string $strategy, array $decisionLog, arr
342342
$this->assertEquals($dataCollector->getAccessDecisionLog(), $expectedDecisionLog, 'Wrong value returned by getAccessDecisionLog');
343343

344344
$this->assertSame(
345-
array_map(function ($classStub) { return (string) $classStub; }, $dataCollector->getVoters()),
345+
array_map(fn ($classStub) => (string) $classStub, $dataCollector->getVoters()),
346346
$expectedVoterClasses,
347347
'Wrong value returned by getVoters'
348348
);

0 commit comments

Comments
 (0)