diff --git a/twig_tweak.api.php b/twig_tweak.api.php index 0965818..a920c3d 100644 --- a/twig_tweak.api.php +++ b/twig_tweak.api.php @@ -24,19 +24,13 @@ use Twig\TwigTest; */ function hook_twig_tweak_functions_alter(array &$functions): void { // A simple way to implement lazy loaded global variables. - $functions[] = new TwigFunction('var', function (string $name) { - $value = NULL; - switch ($name) { - case 'foo': - $value = 'Foo'; - break; - - case 'bar': - $value = 'Bar'; - break; - } - return $value; - }); + $callback = static fn (string $name): ?string => + match ($name) { + 'foo' => 'Foo', + 'bar' => 'Bar', + default => NULL, + }; + $functions[] = new TwigFunction('var', $callback); } /** @@ -58,9 +52,9 @@ function hook_twig_tweak_filters_alter(array &$filters): void { * Twig tests to alter. */ function hook_twig_tweak_tests_alter(array &$tests): void { - $tests[] = new TwigTest('outdated', function (NodeInterface $node): bool { - return \Drupal::time()->getRequestTime() - $node->getCreatedTime() > 3600 * 24 * 365; - }); + $callback = static fn (NodeInterface $node): bool => + \Drupal::time()->getRequestTime() - $node->getCreatedTime() > 3600 * 24 * 365; + $tests[] = new TwigTest('outdated', $callback); } /**