Skip to content

Commit cfe92c3

Browse files
tigitznicolas-grekas
authored andcommitted
Leverage arrow function syntax for closure
1 parent cb23002 commit cfe92c3

24 files changed

+27
-55
lines changed

AcceptHeader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ public function all(): array
115115
*/
116116
public function filter(string $pattern): self
117117
{
118-
return new self(array_filter($this->items, function (AcceptHeaderItem $item) use ($pattern) {
119-
return preg_match($pattern, $item->getValue());
120-
}));
118+
return new self(array_filter($this->items, fn (AcceptHeaderItem $item) => preg_match($pattern, $item->getValue())));
121119
}
122120

123121
/**

FileBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected function convertFileInformation(array|UploadedFile $file): array|Uploa
7575
$file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['error'], false);
7676
}
7777
} else {
78-
$file = array_map(function ($v) { return $v instanceof UploadedFile || \is_array($v) ? $this->convertFileInformation($v) : $v; }, $file);
78+
$file = array_map(fn ($v) => $v instanceof UploadedFile || \is_array($v) ? $this->convertFileInformation($v) : $v, $file);
7979
if (array_keys($keys) === $keys) {
8080
$file = array_filter($file);
8181
}

Request.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -605,9 +605,7 @@ public static function getTrustedHeaderSet(): int
605605
*/
606606
public static function setTrustedHosts(array $hostPatterns)
607607
{
608-
self::$trustedHostPatterns = array_map(function ($hostPattern) {
609-
return sprintf('{%s}i', $hostPattern);
610-
}, $hostPatterns);
608+
self::$trustedHostPatterns = array_map(fn ($hostPattern) => sprintf('{%s}i', $hostPattern), $hostPatterns);
611609
// we need to reset trusted hosts on trusted host patterns change
612610
self::$trustedHosts = [];
613611
}

RequestMatcher.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ public function matchIps(string|array|null $ips)
120120
{
121121
$ips = null !== $ips ? (array) $ips : [];
122122

123-
$this->ips = array_reduce($ips, static function (array $ips, string $ip) {
124-
return array_merge($ips, preg_split('/\s*,\s*/', $ip));
125-
}, []);
123+
$this->ips = array_reduce($ips, static fn (array $ips, string $ip) => array_merge($ips, preg_split('/\s*,\s*/', $ip)), []);
126124
}
127125

128126
/**

RequestMatcher/IpsRequestMatcher.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class IpsRequestMatcher implements RequestMatcherInterface
3030
*/
3131
public function __construct(array|string $ips)
3232
{
33-
$this->ips = array_reduce((array) $ips, static function (array $ips, string $ip) {
34-
return array_merge($ips, preg_split('/\s*,\s*/', $ip));
35-
}, []);
33+
$this->ips = array_reduce((array) $ips, static fn (array $ips, string $ip) => array_merge($ips, preg_split('/\s*,\s*/', $ip)), []);
3634
}
3735

3836
public function matches(Request $request): bool

RequestMatcher/MethodRequestMatcher.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class MethodRequestMatcher implements RequestMatcherInterface
3232
*/
3333
public function __construct(array|string $methods)
3434
{
35-
$this->methods = array_reduce(array_map('strtoupper', (array) $methods), static function (array $methods, string $method) {
36-
return array_merge($methods, preg_split('/\s*,\s*/', $method));
37-
}, []);
35+
$this->methods = array_reduce(array_map('strtoupper', (array) $methods), static fn (array $methods, string $method) => array_merge($methods, preg_split('/\s*,\s*/', $method)), []);
3836
}
3937

4038
public function matches(Request $request): bool

RequestMatcher/SchemeRequestMatcher.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ class SchemeRequestMatcher implements RequestMatcherInterface
3232
*/
3333
public function __construct(array|string $schemes)
3434
{
35-
$this->schemes = array_reduce(array_map('strtolower', (array) $schemes), static function (array $schemes, string $scheme) {
36-
return array_merge($schemes, preg_split('/\s*,\s*/', $scheme));
37-
}, []);
35+
$this->schemes = array_reduce(array_map('strtolower', (array) $schemes), static fn (array $schemes, string $scheme) => array_merge($schemes, preg_split('/\s*,\s*/', $scheme)), []);
3836
}
3937

4038
public function matches(Request $request): bool

Test/Constraint/ResponseCookieValueSame.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ protected function getCookie(Response $response): ?Cookie
6969
{
7070
$cookies = $response->headers->getCookies();
7171

72-
$filteredCookies = array_filter($cookies, function (Cookie $cookie) {
73-
return $cookie->getName() === $this->name && $cookie->getPath() === $this->path && $cookie->getDomain() === $this->domain;
74-
});
72+
$filteredCookies = array_filter($cookies, fn (Cookie $cookie) => $cookie->getName() === $this->name && $cookie->getPath() === $this->path && $cookie->getDomain() === $this->domain);
7573

7674
return reset($filteredCookies) ?: null;
7775
}

Test/Constraint/ResponseHasCookie.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ private function getCookie(Response $response): ?Cookie
6161
{
6262
$cookies = $response->headers->getCookies();
6363

64-
$filteredCookies = array_filter($cookies, function (Cookie $cookie) {
65-
return $cookie->getName() === $this->name && $cookie->getPath() === $this->path && $cookie->getDomain() === $this->domain;
66-
});
64+
$filteredCookies = array_filter($cookies, fn (Cookie $cookie) => $cookie->getName() === $this->name && $cookie->getPath() === $this->path && $cookie->getDomain() === $this->domain);
6765

6866
return reset($filteredCookies) ?: null;
6967
}

Tests/InputBagTest.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ public function testFilterCallback()
6464
public function testFilterClosure()
6565
{
6666
$bag = new InputBag(['foo' => 'bar']);
67-
$result = $bag->filter('foo', null, \FILTER_CALLBACK, ['options' => function ($value) {
68-
return strtoupper($value);
69-
}]);
67+
$result = $bag->filter('foo', null, \FILTER_CALLBACK, ['options' => strtoupper(...)]);
7068

7169
$this->assertSame('BAR', $result);
7270
}

0 commit comments

Comments
 (0)