Skip to content

Commit feb7beb

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 99f9c74 + 8ea8e27 commit feb7beb

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

Authorization/ExpressionLanguageProvider.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,13 @@ class ExpressionLanguageProvider implements ExpressionFunctionProviderInterface
2424
public function getFunctions(): array
2525
{
2626
return [
27-
new ExpressionFunction('is_authenticated', function () {
28-
return '$auth_checker->isGranted("IS_AUTHENTICATED")';
29-
}, function (array $variables) {
30-
return $variables['auth_checker']->isGranted('IS_AUTHENTICATED');
31-
}),
27+
new ExpressionFunction('is_authenticated', fn () => '$auth_checker->isGranted("IS_AUTHENTICATED")', fn (array $variables) => $variables['auth_checker']->isGranted('IS_AUTHENTICATED')),
3228

33-
new ExpressionFunction('is_fully_authenticated', function () {
34-
return '$token && $auth_checker->isGranted("IS_AUTHENTICATED_FULLY")';
35-
}, function (array $variables) {
36-
return $variables['token'] && $variables['auth_checker']->isGranted('IS_AUTHENTICATED_FULLY');
37-
}),
29+
new ExpressionFunction('is_fully_authenticated', fn () => '$token && $auth_checker->isGranted("IS_AUTHENTICATED_FULLY")', fn (array $variables) => $variables['token'] && $variables['auth_checker']->isGranted('IS_AUTHENTICATED_FULLY')),
3830

39-
new ExpressionFunction('is_granted', function ($attributes, $object = 'null') {
40-
return sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object);
41-
}, function (array $variables, $attributes, $object = null) {
42-
return $variables['auth_checker']->isGranted($attributes, $object);
43-
}),
31+
new ExpressionFunction('is_granted', fn ($attributes, $object = 'null') => sprintf('$auth_checker->isGranted(%s, %s)', $attributes, $object), fn (array $variables, $attributes, $object = null) => $variables['auth_checker']->isGranted($attributes, $object)),
4432

45-
new ExpressionFunction('is_remember_me', function () {
46-
return '$token && $auth_checker->isGranted("IS_REMEMBERED")';
47-
}, function (array $variables) {
48-
return $variables['token'] && $variables['auth_checker']->isGranted('IS_REMEMBERED');
49-
}),
33+
new ExpressionFunction('is_remember_me', fn () => '$token && $auth_checker->isGranted("IS_REMEMBERED")', fn (array $variables) => $variables['token'] && $variables['auth_checker']->isGranted('IS_REMEMBERED')),
5034
];
5135
}
5236
}

Tests/Authentication/Token/Storage/UsageTrackingTokenStorageTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ public function testGetSetToken()
6868

6969
public function testWithoutMainRequest()
7070
{
71-
$locator = new class(['request_stack' => function () {
72-
return new RequestStack();
73-
}]) implements ContainerInterface {
71+
$locator = new class(['request_stack' => fn () => new RequestStack()]) implements ContainerInterface {
7472
use ServiceLocatorTrait;
7573
};
7674
$tokenStorage = new TokenStorage();

Tests/Resources/TranslationFilesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testTranslationFileIsValidWithoutEntityLoader($filePath)
4545
public function provideTranslationFiles()
4646
{
4747
return array_map(
48-
function ($filePath) { return (array) $filePath; },
48+
fn ($filePath) => (array) $filePath,
4949
glob(\dirname(__DIR__, 2).'/Resources/translations/*.xlf')
5050
);
5151
}

0 commit comments

Comments
 (0)