Skip to content

Commit 4a85bb3

Browse files
Sync intl scripts
1 parent 243f8f9 commit 4a85bb3

File tree

221 files changed

+546
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+546
-87
lines changed

.github/expected-missing-return-types.diff

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,21 +2328,21 @@ diff --git a/src/Symfony/Component/Console/EventListener/ErrorListener.php b/src
23282328
diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatter.php b/src/Symfony/Component/Console/Formatter/OutputFormatter.php
23292329
--- a/src/Symfony/Component/Console/Formatter/OutputFormatter.php
23302330
+++ b/src/Symfony/Component/Console/Formatter/OutputFormatter.php
2331-
@@ -87,5 +87,5 @@ class OutputFormatter implements WrappableOutputFormatterInterface
2331+
@@ -88,5 +88,5 @@ class OutputFormatter implements WrappableOutputFormatterInterface
23322332
* @return void
23332333
*/
23342334
- public function setDecorated(bool $decorated)
23352335
+ public function setDecorated(bool $decorated): void
23362336
{
23372337
$this->decorated = $decorated;
2338-
@@ -100,5 +100,5 @@ class OutputFormatter implements WrappableOutputFormatterInterface
2338+
@@ -101,5 +101,5 @@ class OutputFormatter implements WrappableOutputFormatterInterface
23392339
* @return void
23402340
*/
23412341
- public function setStyle(string $name, OutputFormatterStyleInterface $style)
23422342
+ public function setStyle(string $name, OutputFormatterStyleInterface $style): void
23432343
{
23442344
$this->styles[strtolower($name)] = $style;
2345-
@@ -127,5 +127,5 @@ class OutputFormatter implements WrappableOutputFormatterInterface
2345+
@@ -128,5 +128,5 @@ class OutputFormatter implements WrappableOutputFormatterInterface
23462346
* @return string
23472347
*/
23482348
- public function formatAndWrap(?string $message, int $width)
@@ -2488,21 +2488,21 @@ diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Compo
24882488
+ public function setHelperSet(?HelperSet $helperSet = null): void
24892489
{
24902490
if (1 > \func_num_args()) {
2491-
@@ -97,5 +97,5 @@ abstract class Helper implements HelperInterface
2491+
@@ -101,5 +101,5 @@ abstract class Helper implements HelperInterface
24922492
* @return string
24932493
*/
24942494
- public static function formatTime(int|float $secs, int $precision = 1)
24952495
+ public static function formatTime(int|float $secs, int $precision = 1): string
24962496
{
24972497
$secs = (int) floor($secs);
2498-
@@ -140,5 +140,5 @@ abstract class Helper implements HelperInterface
2498+
@@ -144,5 +144,5 @@ abstract class Helper implements HelperInterface
24992499
* @return string
25002500
*/
25012501
- public static function formatMemory(int $memory)
25022502
+ public static function formatMemory(int $memory): string
25032503
{
25042504
if ($memory >= 1024 * 1024 * 1024) {
2505-
@@ -160,5 +160,5 @@ abstract class Helper implements HelperInterface
2505+
@@ -164,5 +164,5 @@ abstract class Helper implements HelperInterface
25062506
* @return string
25072507
*/
25082508
- public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string)
@@ -8905,24 +8905,6 @@ diff --git a/src/Symfony/Component/HttpKernel/TerminableInterface.php b/src/Symf
89058905
- public function terminate(Request $request, Response $response);
89068906
+ public function terminate(Request $request, Response $response): void;
89078907
}
8908-
diff --git a/src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php b/src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php
8909-
--- a/src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php
8910-
+++ b/src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php
8911-
@@ -27,4 +27,4 @@ interface BundleCompilerInterface
8912-
* @return void
8913-
*/
8914-
- public function compile(string $sourcePath, string $targetDir);
8915-
+ public function compile(string $sourcePath, string $targetDir): void;
8916-
}
8917-
diff --git a/src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php b/src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php
8918-
--- a/src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php
8919-
+++ b/src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php
8920-
@@ -24,4 +24,4 @@ interface BundleWriterInterface
8921-
* @return void
8922-
*/
8923-
- public function write(string $path, string $locale, mixed $data);
8924-
+ public function write(string $path, string $locale, mixed $data): void;
8925-
}
89268908
diff --git a/src/Symfony/Component/Intl/Transliterator/EmojiTransliterator.php b/src/Symfony/Component/Intl/Transliterator/EmojiTransliterator.php
89278909
--- a/src/Symfony/Component/Intl/Transliterator/EmojiTransliterator.php
89288910
+++ b/src/Symfony/Component/Intl/Transliterator/EmojiTransliterator.php
@@ -9465,28 +9447,28 @@ diff --git a/src/Symfony/Component/Lock/Store/MemcachedStore.php b/src/Symfony/C
94659447
diff --git a/src/Symfony/Component/Lock/Store/MongoDbStore.php b/src/Symfony/Component/Lock/Store/MongoDbStore.php
94669448
--- a/src/Symfony/Component/Lock/Store/MongoDbStore.php
94679449
+++ b/src/Symfony/Component/Lock/Store/MongoDbStore.php
9468-
@@ -209,5 +209,5 @@ class MongoDbStore implements PersistingStoreInterface
9450+
@@ -213,5 +213,5 @@ class MongoDbStore implements PersistingStoreInterface
94699451
* @throws DriverRuntimeException for other driver errors (e.g. connection errors)
94709452
*/
94719453
- public function createTtlIndex(int $expireAfterSeconds = 0)
94729454
+ public function createTtlIndex(int $expireAfterSeconds = 0): void
94739455
{
94749456
$server = $this->getManager()->selectServer();
9475-
@@ -231,5 +231,5 @@ class MongoDbStore implements PersistingStoreInterface
9457+
@@ -235,5 +235,5 @@ class MongoDbStore implements PersistingStoreInterface
94769458
* @throws LockExpiredException when save is called on an expired lock
94779459
*/
94789460
- public function save(Key $key)
94799461
+ public function save(Key $key): void
94809462
{
94819463
$key->reduceLifetime($this->initialTtl);
9482-
@@ -257,5 +257,5 @@ class MongoDbStore implements PersistingStoreInterface
9464+
@@ -261,5 +261,5 @@ class MongoDbStore implements PersistingStoreInterface
94839465
* @throws LockExpiredException
94849466
*/
94859467
- public function putOffExpiration(Key $key, float $ttl)
94869468
+ public function putOffExpiration(Key $key, float $ttl): void
94879469
{
94889470
$key->reduceLifetime($ttl);
9489-
@@ -276,5 +276,5 @@ class MongoDbStore implements PersistingStoreInterface
9471+
@@ -280,5 +280,5 @@ class MongoDbStore implements PersistingStoreInterface
94909472
* @return void
94919473
*/
94929474
- public function delete(Key $key)

src/Symfony/Component/Intl/Data/Bundle/Compiler/BundleCompilerInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ interface BundleCompilerInterface
2323
/**
2424
* Compiles a resource bundle at the given source to the given target
2525
* directory.
26-
*
27-
* @return void
2826
*/
29-
public function compile(string $sourcePath, string $targetDir);
27+
public function compile(string $sourcePath, string $targetDir): void;
3028
}

src/Symfony/Component/Intl/Data/Bundle/Reader/BufferedBundleReader.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
*/
2121
class BufferedBundleReader implements BundleReaderInterface
2222
{
23-
private BundleReaderInterface $reader;
2423
/** @var RingBuffer<string, mixed> */
2524
private RingBuffer $buffer;
2625

27-
public function __construct(BundleReaderInterface $reader, int $bufferSize)
28-
{
29-
$this->reader = $reader;
26+
public function __construct(
27+
private BundleReaderInterface $reader,
28+
int $bufferSize,
29+
) {
3030
$this->buffer = new RingBuffer($bufferSize);
3131
}
3232

src/Symfony/Component/Intl/Data/Bundle/Reader/BundleEntryReader.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
*/
2929
class BundleEntryReader implements BundleEntryReaderInterface
3030
{
31-
private BundleReaderInterface $reader;
32-
3331
/**
3432
* A mapping of locale aliases to locales.
3533
*/
@@ -38,9 +36,9 @@ class BundleEntryReader implements BundleEntryReaderInterface
3836
/**
3937
* Creates an entry reader based on the given resource bundle reader.
4038
*/
41-
public function __construct(BundleReaderInterface $reader)
42-
{
43-
$this->reader = $reader;
39+
public function __construct(
40+
private BundleReaderInterface $reader,
41+
) {
4442
}
4543

4644
/**

src/Symfony/Component/Intl/Data/Bundle/Writer/BundleWriterInterface.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,5 @@
2020
*/
2121
interface BundleWriterInterface
2222
{
23-
/**
24-
* @return void
25-
*/
26-
public function write(string $path, string $locale, mixed $data);
23+
public function write(string $path, string $locale, mixed $data): void;
2724
}

src/Symfony/Component/Intl/Data/Bundle/Writer/PhpBundleWriter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ class PhpBundleWriter implements BundleWriterInterface
2525
public function write(string $path, string $locale, mixed $data): void
2626
{
2727
$template = <<<'TEMPLATE'
28-
<?php
28+
<?php
2929
30-
return %s;
30+
return %s;
3131

32-
TEMPLATE;
32+
TEMPLATE;
3333

3434
if ($data instanceof \Traversable) {
3535
$data = iterator_to_array($data);

src/Symfony/Component/Intl/Data/Generator/AbstractDataGenerator.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@
2727
*/
2828
abstract class AbstractDataGenerator
2929
{
30-
private BundleCompilerInterface $compiler;
31-
private string $dirName;
32-
33-
public function __construct(BundleCompilerInterface $compiler, string $dirName)
34-
{
35-
$this->compiler = $compiler;
36-
$this->dirName = $dirName;
30+
public function __construct(
31+
private BundleCompilerInterface $compiler,
32+
private string $dirName,
33+
) {
3734
}
3835

3936
public function generateData(GeneratorConfig $config): void

src/Symfony/Component/Intl/Data/Generator/GeneratorConfig.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@
2222
*/
2323
class GeneratorConfig
2424
{
25-
private string $sourceDir;
26-
private string $icuVersion;
27-
2825
/**
2926
* @var BundleWriterInterface[]
3027
*/
3128
private array $bundleWriters = [];
3229

33-
public function __construct(string $sourceDir, string $icuVersion)
34-
{
35-
$this->sourceDir = $sourceDir;
36-
$this->icuVersion = $icuVersion;
30+
public function __construct(
31+
private string $sourceDir,
32+
private string $icuVersion,
33+
) {
3734
}
3835

3936
/**

src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ class RegionDataGenerator extends AbstractDataGenerator
5656
'QO' => true, // Outlying Oceania
5757
'XA' => true, // Pseudo-Accents
5858
'XB' => true, // Pseudo-Bidi
59-
'XK' => true, // Kosovo
6059
// Misc
6160
'ZZ' => true, // Unknown Region
6261
];
6362

63+
private const USER_ASSIGNED = [
64+
'XK' => true, // Kosovo
65+
];
66+
6467
// @see https://en.wikipedia.org/wiki/ISO_3166-1_numeric#Withdrawn_codes
6568
private const WITHDRAWN_CODES = [
6669
128, // Canton and Enderbury Islands
@@ -97,7 +100,7 @@ class RegionDataGenerator extends AbstractDataGenerator
97100

98101
public static function isValidCountryCode(int|string|null $region): bool
99102
{
100-
if (isset(self::DENYLIST[$region])) {
103+
if (isset(self::DENYLIST[$region]) || isset(self::USER_ASSIGNED[$region])) {
101104
return false;
102105
}
103106

@@ -109,6 +112,11 @@ public static function isValidCountryCode(int|string|null $region): bool
109112
return true;
110113
}
111114

115+
public static function isUserAssignedCountryCode(int|string|null $region): bool
116+
{
117+
return isset(self::USER_ASSIGNED[$region]);
118+
}
119+
112120
protected function scanLocales(LocaleScanner $scanner, string $sourceDir): array
113121
{
114122
return $scanner->scanLocales($sourceDir.'/region');
@@ -131,9 +139,7 @@ protected function generateDataForLocale(BundleEntryReaderInterface $reader, str
131139

132140
// isset() on \ResourceBundle returns true even if the value is null
133141
if (isset($localeBundle['Countries']) && null !== $localeBundle['Countries']) {
134-
$data = [
135-
'Names' => $this->generateRegionNames($localeBundle),
136-
];
142+
$data = $this->generateRegionNames($localeBundle);
137143

138144
$this->regionCodes = array_merge($this->regionCodes, array_keys($data['Names']));
139145

@@ -153,23 +159,39 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
153159
$metadataBundle = $reader->read($tempDir, 'metadata');
154160

155161
$this->regionCodes = array_unique($this->regionCodes);
156-
157162
sort($this->regionCodes);
158163

159164
$alpha2ToAlpha3 = $this->generateAlpha2ToAlpha3Mapping(array_flip($this->regionCodes), $metadataBundle);
165+
$userAssignedAlpha2ToAlpha3 = $this->generateAlpha2ToAlpha3Mapping(self::USER_ASSIGNED, $metadataBundle);
166+
160167
$alpha3ToAlpha2 = array_flip($alpha2ToAlpha3);
161168
asort($alpha3ToAlpha2);
169+
$userAssignedAlpha3toAlpha2 = array_flip($userAssignedAlpha2ToAlpha3);
170+
asort($userAssignedAlpha3toAlpha2);
162171

163172
$alpha2ToNumeric = $this->generateAlpha2ToNumericMapping(array_flip($this->regionCodes), $metadataBundle);
173+
$userAssignedAlpha2ToNumeric = $this->generateAlpha2ToNumericMapping(self::USER_ASSIGNED, $metadataBundle);
174+
164175
$numericToAlpha2 = [];
165176
foreach ($alpha2ToNumeric as $alpha2 => $numeric) {
166177
// Add underscore prefix to force keys with leading zeros to remain as string keys.
167178
$numericToAlpha2['_'.$numeric] = $alpha2;
168179
}
180+
$userAssignedNumericToAlpha2 = [];
181+
foreach ($userAssignedAlpha2ToNumeric as $alpha2 => $numeric) {
182+
// Add underscore prefix to force keys with leading zeros to remain as string keys.
183+
$userAssignedNumericToAlpha2['_'.$numeric] = $alpha2;
184+
}
169185

170186
asort($numericToAlpha2);
187+
asort($userAssignedNumericToAlpha2);
171188

172189
return [
190+
'UserAssignedRegions' => array_keys(self::USER_ASSIGNED),
191+
'UserAssignedAlpha2ToAlpha3' => $userAssignedAlpha2ToAlpha3,
192+
'UserAssignedAlpha3ToAlpha2' => $userAssignedAlpha3toAlpha2,
193+
'UserAssignedAlpha2ToNumeric' => $userAssignedAlpha2ToNumeric,
194+
'UserAssignedNumericToAlpha2' => $userAssignedNumericToAlpha2,
173195
'Regions' => $this->regionCodes,
174196
'Alpha2ToAlpha3' => $alpha2ToAlpha3,
175197
'Alpha3ToAlpha2' => $alpha3ToAlpha2,
@@ -181,14 +203,19 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
181203
protected function generateRegionNames(ArrayAccessibleResourceBundle $localeBundle): array
182204
{
183205
$unfilteredRegionNames = iterator_to_array($localeBundle['Countries']);
184-
$regionNames = [];
206+
$regionNames = ['UserAssignedNames' => [], 'Names' => []];
185207

186208
foreach ($unfilteredRegionNames as $region => $regionName) {
187-
if (!self::isValidCountryCode($region)) {
209+
if (!self::isValidCountryCode($region) && !self::isUserAssignedCountryCode($region)) {
188210
continue;
189211
}
190212

191-
$regionNames[$region] = $regionName;
213+
if (self::isUserAssignedCountryCode($region)) {
214+
$regionNames['UserAssignedNames'][$region] = $regionName;
215+
continue;
216+
}
217+
218+
$regionNames['Names'][$region] = $regionName;
192219
}
193220

194221
return $regionNames;
@@ -204,7 +231,9 @@ private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessible
204231
$country = $data['replacement'];
205232

206233
if (2 === \strlen($country) && 3 === \strlen($alias) && 'overlong' === $data['reason']) {
207-
if (isset(self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country])) {
234+
if (isset($countries[$country]) && self::isUserAssignedCountryCode($country)) {
235+
$alpha2ToAlpha3[$country] = $alias;
236+
} elseif (isset($countries[$country]) && !self::isUserAssignedCountryCode($country) && isset(self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country])) {
208237
// Validate to prevent typos
209238
if (!isset($aliases[self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country]])) {
210239
throw new RuntimeException('The statically set three-letter mapping '.self::PREFERRED_ALPHA2_TO_ALPHA3_MAPPING[$country].' for the country code '.$country.' seems to be invalid. Typo?');
@@ -242,7 +271,7 @@ private function generateAlpha2ToNumericMapping(array $countries, ArrayAccessibl
242271
continue;
243272
}
244273

245-
if (\in_array($alias, self::WITHDRAWN_CODES)) {
274+
if (\in_array($alias, self::WITHDRAWN_CODES, true)) {
246275
continue;
247276
}
248277

src/Symfony/Component/Intl/Data/Generator/TimezoneDataGenerator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Symfony\Component\Intl\Data\Util\ArrayAccessibleResourceBundle;
1818
use Symfony\Component\Intl\Data\Util\LocaleScanner;
1919
use Symfony\Component\Intl\Exception\MissingResourceException;
20-
use Symfony\Component\Intl\Locale;
2120

2221
/**
2322
* The rule for compiling the zone bundle.
@@ -128,20 +127,16 @@ protected function generateDataForRoot(BundleEntryReaderInterface $reader, strin
128127

129128
protected function generateDataForMeta(BundleEntryReaderInterface $reader, string $tempDir): ?array
130129
{
131-
$rootBundle = $reader->read($tempDir, 'root');
132-
133130
$this->zoneIds = array_unique($this->zoneIds);
134131

135132
sort($this->zoneIds);
136133
ksort($this->zoneToCountryMapping);
137134

138-
$data = [
135+
return [
139136
'Zones' => $this->zoneIds,
140137
'ZoneToCountry' => $this->zoneToCountryMapping,
141138
'CountryToZone' => self::generateCountryToZoneMapping($this->zoneToCountryMapping),
142139
];
143-
144-
return $data;
145140
}
146141

147142
private function generateZones(BundleEntryReaderInterface $reader, string $tempDir, string $locale): array

0 commit comments

Comments
 (0)