Skip to content

Commit b869011

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 64d39cb + e454ad9 commit b869011

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

Csp/ContentSecurityPolicyHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,7 @@ private function generateNonce(): string
180180
*/
181181
private function generateCspHeader(array $directives): string
182182
{
183-
return array_reduce(array_keys($directives), function ($res, $name) use ($directives) {
184-
return ('' !== $res ? $res.'; ' : '').sprintf('%s %s', $name, implode(' ', $directives[$name]));
185-
}, '');
183+
return array_reduce(array_keys($directives), fn ($res, $name) => ('' !== $res ? $res.'; ' : '').sprintf('%s %s', $name, implode(' ', $directives[$name])), '');
186184
}
187185

188186
/**

Tests/Controller/ProfilerControllerTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ public function testReturns404onTokenNotFound($withCsp)
188188
$profiler
189189
->expects($this->exactly(2))
190190
->method('loadProfile')
191-
->willReturnCallback(function ($token) {
192-
return 'found' == $token ? new Profile($token) : null;
193-
})
191+
->willReturnCallback(fn ($token) => 'found' == $token ? new Profile($token) : null)
194192
;
195193

196194
$controller = $this->createController($profiler, $twig, $withCsp);

Tests/Resources/IconTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ public function testIconFileContents($iconFilePath)
3434

3535
public function provideIconFilePaths()
3636
{
37-
return array_map(function ($filePath) { return (array) $filePath; }, glob(__DIR__.'/../../Resources/views/Icon/*.svg'));
37+
return array_map(fn ($filePath) => (array) $filePath, glob(__DIR__.'/../../Resources/views/Icon/*.svg'));
3838
}
3939
}

0 commit comments

Comments
 (0)