Skip to content

Commit 8ea8e27

Browse files
tigitznicolas-grekas
authored andcommitted
Leverage arrow function syntax for closure
1 parent ffd1e14 commit 8ea8e27

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)