Skip to content

Commit 319a0e9

Browse files
tigitznicolas-grekas
authored andcommitted
Leverage arrow function syntax for closure
1 parent 863219f commit 319a0e9

File tree

6 files changed

+20
-30
lines changed

6 files changed

+20
-30
lines changed

AbstractUnicodeString.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ public function title(bool $allWords = false): static
360360

361361
$limit = $allWords ? -1 : 1;
362362

363-
$str->string = preg_replace_callback('/\b./u', static function (array $m): string {
364-
return mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8');
365-
}, $str->string, $limit);
363+
$str->string = preg_replace_callback('/\b./u', static fn (array $m): string => mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8'), $str->string, $limit);
366364

367365
return $str;
368366
}

Resources/WcswidthDataGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ private function format(array $rawData): array
104104
return [hexdec($start), hexdec($end)];
105105
}, $rawData);
106106

107-
usort($data, static function (array $a, array $b): int {
108-
return $a[0] - $b[0];
109-
});
107+
usort($data, static fn (array $a, array $b): int => $a[0] - $b[0]);
110108

111109
return $data;
112110
}

Slugger/AsciiSlugger.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ public function slug(string $string, string $separator = '-', string $locale = n
121121
// If the symbols map is passed as a closure, there is no need to fallback to the parent locale
122122
// as the closure can just provide substitutions for all locales of interest.
123123
$symbolsMap = $this->symbolsMap;
124-
array_unshift($transliterator, static function ($s) use ($symbolsMap, $locale) {
125-
return $symbolsMap($s, $locale);
126-
});
124+
array_unshift($transliterator, static fn ($s) => $symbolsMap($s, $locale));
127125
}
128126

129127
$unicodeString = (new UnicodeString($string))->ascii($transliterator);

Tests/AbstractAsciiTestCase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,7 @@ public static function provideReplaceMatches()
993993
['April,15,2003', 'April 15, 2003', '/(\w+) (\d+), (\d+)/i', '${1},$2,$3'],
994994
['5/27/1999', '1999-5-27', '/(19|20)(\d{2})-(\d{1,2})-(\d{1,2})/', '\3/\4/\1\2'],
995995
['Copyright 2000', 'Copyright 1999', '([0-9]+)', '2000'],
996-
['hello world! this is a test', 'HELLO WORLD! THIS is a test', '/\b([A-Z]+)\b/', function ($word) {
997-
return strtolower($word[1]);
998-
}],
996+
['hello world! this is a test', 'HELLO WORLD! THIS is a test', '/\b([A-Z]+)\b/', fn ($word) => strtolower($word[1])],
999997
['COPYRIGHT 1999', 'Copyright 1999', '/[a-z]/', function ($matches) {
1000998
foreach ($matches as $match) {
1001999
return strtoupper($match);

Tests/AbstractUnicodeTestCase.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ public function testAscii()
4444

4545
public function testAsciiClosureRule()
4646
{
47-
$rule = function ($c) {
48-
return str_replace('', 'OE', $c);
49-
};
47+
$rule = fn ($c) => str_replace('', 'OE', $c);
5048

5149
$s = static::createFromString('Dieser Wert sollte größer oder gleich');
5250
$this->assertSame('Dieser Wert sollte grOEsser oder gleich', (string) $s->ascii([$rule]));

Tests/LazyStringTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ public function testLazyString()
2929
$this->assertSame(1, $count);
3030
}
3131

32+
/**
33+
* @runInSeparateProcess
34+
*/
35+
public function testReturnTypeError()
36+
{
37+
ErrorHandler::register();
38+
39+
$s = LazyString::fromCallable(fn () => []);
40+
41+
$this->expectException(\TypeError::class);
42+
$this->expectExceptionMessage('Return value of '.__NAMESPACE__.'\{closure}() passed to '.LazyString::class.'::fromCallable() must be of the type string, array returned.');
43+
44+
(string) $s;
45+
}
46+
3247
public function testLazyCallable()
3348
{
3449
$count = 0;
@@ -55,21 +70,6 @@ public function __invoke()
5570
$this->assertSame(1, $count);
5671
}
5772

58-
/**
59-
* @runInSeparateProcess
60-
*/
61-
public function testReturnTypeError()
62-
{
63-
ErrorHandler::register();
64-
65-
$s = LazyString::fromCallable(function () { return []; });
66-
67-
$this->expectException(\TypeError::class);
68-
$this->expectExceptionMessage('Return value of '.__NAMESPACE__.'\{closure}() passed to '.LazyString::class.'::fromCallable() must be of the type string, array returned.');
69-
70-
(string) $s;
71-
}
72-
7373
public function testFromStringable()
7474
{
7575
$this->assertInstanceOf(LazyString::class, LazyString::fromStringable('abc'));

0 commit comments

Comments
 (0)