Skip to content

Commit 49c2c14

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 211a76a + 889bca5 commit 49c2c14

8 files changed

+16
-30
lines changed

GenericRuntime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getResolver(callable $callable, \ReflectionFunction $reflector =
113113

114114
public function getRunner(?object $application): RunnerInterface
115115
{
116-
$application ??= static function () { return 0; };
116+
$application ??= static fn () => 0;
117117

118118
if ($application instanceof RunnerInterface) {
119119
return $application;

Tests/phpt/dotenv_overload.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@
1919

2020
require __DIR__.'/autoload.php';
2121

22-
return function (Request $request, array $context) {
23-
return new Response('OK Request '.$context['SOME_VAR']);
24-
};
22+
return fn (Request $request, array $context) => new Response('OK Request '.$context['SOME_VAR']);

Tests/phpt/dotenv_overload_command_debug_exists_0_to_1.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
require __DIR__.'/autoload.php';
2222

23-
return static function (Command $command, OutputInterface $output, array $context): Command {
24-
return $command->setCode(static function () use ($output, $context): void {
25-
$output->writeln($context['DEBUG_ENABLED']);
26-
});
27-
};
23+
return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void {
24+
$output->writeln($context['DEBUG_ENABLED']);
25+
});

Tests/phpt/dotenv_overload_command_debug_exists_1_to_0.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
require __DIR__.'/autoload.php';
2222

23-
return static function (Command $command, OutputInterface $output, array $context): Command {
24-
return $command->setCode(static function () use ($output, $context): void {
25-
$output->writeln($context['DEBUG_MODE']);
26-
});
27-
};
23+
return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void {
24+
$output->writeln($context['DEBUG_MODE']);
25+
});

Tests/phpt/dotenv_overload_command_env_exists.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020

2121
require __DIR__.'/autoload.php';
2222

23-
return static function (Command $command, OutputInterface $output, array $context): Command {
24-
return $command->setCode(static function () use ($output, $context): void {
25-
$output->writeln($context['ENV_MODE']);
26-
});
27-
};
23+
return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void {
24+
$output->writeln($context['ENV_MODE']);
25+
});

Tests/phpt/dotenv_overload_command_no_debug.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
require __DIR__.'/autoload.php';
2121

22-
return static function (Command $command, OutputInterface $output, array $context): Command {
23-
return $command->setCode(static function () use ($output, $context): void {
24-
$output->writeln($context['DEBUG_ENABLED']);
25-
});
26-
};
22+
return static fn (Command $command, OutputInterface $output, array $context): Command => $command->setCode(static function () use ($output, $context): void {
23+
$output->writeln($context['DEBUG_ENABLED']);
24+
});

Tests/phpt/kernel.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = tr
3030
}
3131
}
3232

33-
return function (array $context) {
34-
return new TestKernel($context['SOME_VAR']);
35-
};
33+
return fn (array $context) => new TestKernel($context['SOME_VAR']);

Tests/phpt/request.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@
1414

1515
require __DIR__.'/autoload.php';
1616

17-
return function (Request $request, array $context) {
18-
return new Response('OK Request '.$context['SOME_VAR']);
19-
};
17+
return fn (Request $request, array $context) => new Response('OK Request '.$context['SOME_VAR']);

0 commit comments

Comments
 (0)