Skip to content

Commit 749e5e3

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 bc62067 + 732e1b9 commit 749e5e3

File tree

9 files changed

+22
-36
lines changed

9 files changed

+22
-36
lines changed

Data/Generator/CurrencyDataGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
112112

113113
private function generateSymbolNamePairs(ArrayAccessibleResourceBundle $rootBundle): array
114114
{
115-
$symbolNamePairs = array_map(function ($pair) {
116-
return \array_slice(iterator_to_array($pair), 0, 2);
117-
}, iterator_to_array($rootBundle['Currencies']));
115+
$symbolNamePairs = array_map(fn ($pair) => \array_slice(iterator_to_array($pair), 0, 2), iterator_to_array($rootBundle['Currencies']));
118116

119117
// Remove unwanted currencies
120118
$symbolNamePairs = array_diff_key($symbolNamePairs, self::DENYLIST);

Data/Generator/LanguageDataGenerator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ private static function generateLanguageNames(ArrayAccessibleResourceBundle $loc
169169

170170
private function generateAlpha3Codes(array $languageCodes, ArrayAccessibleResourceBundle $metadataBundle): array
171171
{
172-
$alpha3Codes = array_flip(array_filter($languageCodes, static function (string $language): bool {
173-
return 3 === \strlen($language);
174-
}));
172+
$alpha3Codes = array_flip(array_filter($languageCodes, static fn (string $language): bool => 3 === \strlen($language)));
175173

176174
foreach ($metadataBundle['alias']['language'] as $alias => $data) {
177175
if (3 === \strlen($alias) && 'overlong' === $data['reason']) {

Data/Util/LocaleScanner.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ public function scanLocales(string $sourceDir): array
4646
array_walk($locales, function (&$locale) { $locale = basename($locale, '.txt'); });
4747

4848
// Remove non-locales
49-
$locales = array_filter($locales, function ($locale) {
50-
return preg_match('/^[a-z]{2}(_.+)?$/', $locale);
51-
});
49+
$locales = array_filter($locales, fn ($locale) => preg_match('/^[a-z]{2}(_.+)?$/', $locale));
5250

5351
sort($locales);
5452

Resources/bin/update-data.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@
7777
echo "Git clone to {$repoDir} complete.\n";
7878
}
7979

80-
$gitTag = $git->getLastTag(function ($tag) {
81-
return preg_match('#^release-[0-9]{1,}-[0-9]{1}$#', $tag);
82-
});
80+
$gitTag = $git->getLastTag(fn ($tag) => preg_match('#^release-[0-9]{1,}-[0-9]{1}$#', $tag));
8381
$shortIcuVersion = strip_minor_versions(preg_replace('#release-([0-9]{1,})-([0-9]{1,})#', '$1.$2', $gitTag));
8482

8583
echo "Checking out `{$gitTag}` for version `{$shortIcuVersion}`...\n";

Tests/CurrenciesTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ public function testGetSymbol($displayLocale)
677677
public function provideCurrencies()
678678
{
679679
return array_map(
680-
function ($currency) { return [$currency]; },
680+
fn ($currency) => [$currency],
681681
self::CURRENCIES
682682
);
683683
}
@@ -704,7 +704,7 @@ public function testGetRoundingIncrement($currency)
704704
public function provideCurrenciesWithNumericEquivalent()
705705
{
706706
return array_map(
707-
function ($value) { return [$value]; },
707+
fn ($value) => [$value],
708708
array_keys(self::ALPHA3_TO_NUMERIC)
709709
);
710710
}
@@ -720,7 +720,7 @@ public function testGetNumericCode($currency)
720720
public function provideCurrenciesWithoutNumericEquivalent()
721721
{
722722
return array_map(
723-
function ($value) { return [$value]; },
723+
fn ($value) => [$value],
724724
array_diff(self::CURRENCIES, array_keys(self::ALPHA3_TO_NUMERIC))
725725
);
726726
}
@@ -739,7 +739,7 @@ public function provideValidNumericCodes()
739739
$numericToAlpha3 = $this->getNumericToAlpha3Mapping();
740740

741741
return array_map(
742-
function ($numeric, $alpha3) { return [$numeric, $alpha3]; },
742+
fn ($numeric, $alpha3) => [$numeric, $alpha3],
743743
array_keys($numericToAlpha3),
744744
$numericToAlpha3
745745
);
@@ -765,7 +765,7 @@ public function provideInvalidNumericCodes()
765765
$invalidNumericCodes = array_diff(range(0, 1000), $validNumericCodes);
766766

767767
return array_map(
768-
function ($value) { return [$value]; },
768+
fn ($value) => [$value],
769769
$invalidNumericCodes
770770
);
771771
}

Tests/LanguagesTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ public function testGetNameDefaultLocale()
17451745
public function provideLanguagesWithAlpha3Equivalent()
17461746
{
17471747
return array_map(
1748-
function ($value) { return [$value]; },
1748+
fn ($value) => [$value],
17491749
array_keys(self::ALPHA2_TO_ALPHA3)
17501750
);
17511751
}
@@ -1761,7 +1761,7 @@ public function testGetAlpha3Code($language)
17611761
public function provideLanguagesWithoutAlpha3Equivalent()
17621762
{
17631763
return array_map(
1764-
function ($value) { return [$value]; },
1764+
fn ($value) => [$value],
17651765
array_diff(self::LANGUAGES, array_keys(self::ALPHA2_TO_ALPHA3))
17661766
);
17671767
}
@@ -1795,7 +1795,7 @@ public function testGetAlpha3Codes()
17951795
public function provideLanguagesWithAlpha2Equivalent()
17961796
{
17971797
return array_map(
1798-
function ($value) { return [$value]; },
1798+
fn ($value) => [$value],
17991799
array_keys(self::ALPHA3_TO_ALPHA2)
18001800
);
18011801
}
@@ -1811,7 +1811,7 @@ public function testGetAlpha2Code($language)
18111811
public function provideLanguagesWithoutAlpha2Equivalent()
18121812
{
18131813
return array_map(
1814-
function ($value) { return [$value]; },
1814+
fn ($value) => [$value],
18151815
array_diff(self::ALPHA3_CODES, array_keys(self::ALPHA3_TO_ALPHA2))
18161816
);
18171817
}

Tests/ResourceBundleTestCase.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -752,15 +752,15 @@ protected function tearDown(): void
752752
public function provideLocales()
753753
{
754754
return array_map(
755-
function ($locale) { return [$locale]; },
755+
fn ($locale) => [$locale],
756756
$this->getLocales()
757757
);
758758
}
759759

760760
public function provideLocaleAliases()
761761
{
762762
return array_map(
763-
function ($alias, $ofLocale) { return [$alias, $ofLocale]; },
763+
fn ($alias, $ofLocale) => [$alias, $ofLocale],
764764
array_keys($this->getLocaleAliases()),
765765
$this->getLocaleAliases()
766766
);
@@ -769,7 +769,7 @@ function ($alias, $ofLocale) { return [$alias, $ofLocale]; },
769769
public function provideRootLocales()
770770
{
771771
return array_map(
772-
function ($locale) { return [$locale]; },
772+
fn ($locale) => [$locale],
773773
$this->getRootLocales()
774774
);
775775
}
@@ -787,10 +787,8 @@ protected function getLocaleAliases()
787787
protected function getRootLocales()
788788
{
789789
if (null === self::$rootLocales) {
790-
self::$rootLocales = array_filter($this->getLocales(), function ($locale) {
791-
// no locales for which fallback is possible (e.g "en_GB")
792-
return !str_contains($locale, '_');
793-
});
790+
self::$rootLocales = array_filter($this->getLocales(), fn ($locale) => // no locales for which fallback is possible (e.g "en_GB")
791+
!str_contains($locale, '_'));
794792
}
795793

796794
return self::$rootLocales;

Tests/TimezonesTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,7 @@ public function testGetCountryCodeAvailability(string $timezone)
641641

642642
public function provideTimezones(): iterable
643643
{
644-
return array_map(function ($timezone) {
645-
return [$timezone];
646-
}, self::ZONES);
644+
return array_map(fn ($timezone) => [$timezone], self::ZONES);
647645
}
648646

649647
/**
@@ -659,9 +657,7 @@ public function testForCountryCodeAvailability(string $country)
659657

660658
public function provideCountries(): iterable
661659
{
662-
return array_map(function ($country) {
663-
return [$country];
664-
}, Countries::getCountryCodes());
660+
return array_map(fn ($country) => [$country], Countries::getCountryCodes());
665661
}
666662

667663
public function testGetRawOffsetChangeTimeCountry()

Tests/Util/GitRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ public function testItClonesTheRepository()
5858
$this->assertNotEmpty($git->getLastAuthor());
5959
$this->assertInstanceOf(\DateTimeImmutable::class, $git->getLastAuthoredDate());
6060
$this->assertStringMatchesFormat('v%s', $git->getLastTag());
61-
$this->assertStringMatchesFormat('v3%s', $git->getLastTag(function ($tag) { return str_starts_with($tag, 'v3'); }));
61+
$this->assertStringMatchesFormat('v3%s', $git->getLastTag(fn ($tag) => str_starts_with($tag, 'v3')));
6262
}
6363

6464
public function testItCheckoutsToTheLastTag()
6565
{
6666
$git = GitRepository::download(self::REPO_URL, $this->targetDir);
6767
$lastCommitHash = $git->getLastCommitHash();
68-
$lastV3Tag = $git->getLastTag(function ($tag) { return str_starts_with($tag, 'v3'); });
68+
$lastV3Tag = $git->getLastTag(fn ($tag) => str_starts_with($tag, 'v3'));
6969

7070
$git->checkout($lastV3Tag);
7171

0 commit comments

Comments
 (0)