Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 851f0ff

Browse filesBrowse files
bug #60711 [Intl] Ensure data consistency between alpha and numeric codes (llupa)
This PR was merged into the 6.4 branch. Discussion ---------- [Intl] Ensure data consistency between alpha and numeric codes | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #60696 | License | MIT Commits ------- 7d67017 [Intl] Ensure data consistency between alpha and numeric codes
2 parents 3f912bf + 7d67017 commit 851f0ff
Copy full SHA for 851f0ff

File tree

Expand file treeCollapse file tree

3 files changed

+20
-111
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+20
-111
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Data/Generator/RegionDataGenerator.php
+6-2Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function generateDataForMeta(BundleEntryReaderInterface $reader, strin
160160
$alpha3ToAlpha2 = array_flip($alpha2ToAlpha3);
161161
asort($alpha3ToAlpha2);
162162

163-
$alpha2ToNumeric = $this->generateAlpha2ToNumericMapping($metadataBundle);
163+
$alpha2ToNumeric = $this->generateAlpha2ToNumericMapping(array_flip($this->regionCodes), $metadataBundle);
164164
$numericToAlpha2 = [];
165165
foreach ($alpha2ToNumeric as $alpha2 => $numeric) {
166166
// Add underscore prefix to force keys with leading zeros to remain as string keys.
@@ -231,7 +231,7 @@ private function generateAlpha2ToAlpha3Mapping(array $countries, ArrayAccessible
231231
return $alpha2ToAlpha3;
232232
}
233233

234-
private function generateAlpha2ToNumericMapping(ArrayAccessibleResourceBundle $metadataBundle): array
234+
private function generateAlpha2ToNumericMapping(array $countries, ArrayAccessibleResourceBundle $metadataBundle): array
235235
{
236236
$aliases = iterator_to_array($metadataBundle['alias']['territory']);
237237

@@ -250,6 +250,10 @@ private function generateAlpha2ToNumericMapping(ArrayAccessibleResourceBundle $m
250250
continue;
251251
}
252252

253+
if (!isset($countries[$data['replacement']])) {
254+
continue;
255+
}
256+
253257
if ('deprecated' === $data['reason']) {
254258
continue;
255259
}

‎src/Symfony/Component/Intl/Resources/data/regions/meta.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Resources/data/regions/meta.php
-72Lines changed: 0 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/Symfony/Component/Intl/Tests/CountriesTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Intl/Tests/CountriesTest.php
+14-37Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,6 @@ class CountriesTest extends ResourceBundleTestCase
527527
];
528528

529529
private const ALPHA2_TO_NUMERIC = [
530-
'AA' => '958',
531530
'AD' => '020',
532531
'AE' => '784',
533532
'AF' => '004',
@@ -715,18 +714,6 @@ class CountriesTest extends ResourceBundleTestCase
715714
'PW' => '585',
716715
'PY' => '600',
717716
'QA' => '634',
718-
'QM' => '959',
719-
'QN' => '960',
720-
'QP' => '962',
721-
'QQ' => '963',
722-
'QR' => '964',
723-
'QS' => '965',
724-
'QT' => '966',
725-
'QV' => '968',
726-
'QW' => '969',
727-
'QX' => '970',
728-
'QY' => '971',
729-
'QZ' => '972',
730717
'RE' => '638',
731718
'RO' => '642',
732719
'RS' => '688',
@@ -784,36 +771,26 @@ class CountriesTest extends ResourceBundleTestCase
784771
'VU' => '548',
785772
'WF' => '876',
786773
'WS' => '882',
787-
'XC' => '975',
788-
'XD' => '976',
789-
'XE' => '977',
790-
'XF' => '978',
791-
'XG' => '979',
792-
'XH' => '980',
793-
'XI' => '981',
794-
'XJ' => '982',
795-
'XL' => '984',
796-
'XM' => '985',
797-
'XN' => '986',
798-
'XO' => '987',
799-
'XP' => '988',
800-
'XQ' => '989',
801-
'XR' => '990',
802-
'XS' => '991',
803-
'XT' => '992',
804-
'XU' => '993',
805-
'XV' => '994',
806-
'XW' => '995',
807-
'XX' => '996',
808-
'XY' => '997',
809-
'XZ' => '998',
810774
'YE' => '887',
811775
'YT' => '175',
812776
'ZA' => '710',
813777
'ZM' => '894',
814778
'ZW' => '716',
815779
];
816780

781+
public function testAllGettersGenerateTheSameDataSetCount()
782+
{
783+
$alpha2Count = count(Countries::getCountryCodes());
784+
$alpha3Count = count(Countries::getAlpha3Codes());
785+
$numericCodesCount = count(Countries::getNumericCodes());
786+
$namesCount = count(Countries::getNames());
787+
788+
// we base all on Name count since it is the first to be generated
789+
$this->assertEquals($namesCount, $alpha2Count, 'Alpha 2 count does not match');
790+
$this->assertEquals($namesCount, $alpha3Count, 'Alpha 3 count does not match');
791+
$this->assertEquals($namesCount, $numericCodesCount, 'Numeric codes count does not match');
792+
}
793+
817794
public function testGetCountryCodes()
818795
{
819796
$this->assertSame(self::COUNTRIES, Countries::getCountryCodes());
@@ -992,7 +969,7 @@ public function testGetNumericCode()
992969
public function testNumericCodeExists()
993970
{
994971
$this->assertTrue(Countries::numericCodeExists('250'));
995-
$this->assertTrue(Countries::numericCodeExists('982'));
972+
$this->assertTrue(Countries::numericCodeExists('008'));
996973
$this->assertTrue(Countries::numericCodeExists('716'));
997974
$this->assertTrue(Countries::numericCodeExists('036'));
998975
$this->assertFalse(Countries::numericCodeExists('667'));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.