Skip to content

Commit

Permalink
Merge pull request #66 from giggsey/upstream-8.13.40
Browse files Browse the repository at this point in the history
Upstream metadata changes from Google for v8.13.40
  • Loading branch information
giggsey authored Jul 1, 2024
2 parents 5915119 + 9e7f353 commit a6e1029
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 19 deletions.
2 changes: 1 addition & 1 deletion METADATA-VERSION.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
* For more information, look at the phing tasks in build.xml
* @internal
*/
return 'v8.13.39';
return 'v8.13.40';
18 changes: 15 additions & 3 deletions src/PhoneNumberUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ class PhoneNumberUtil
86, // China
];

/**
* Set of country codes that doesn't have national prefix, but it has area codes.
*/
protected const COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES = [
52, // Mexico
];

/**
* Set of country calling codes that have geographically assigned mobile numbers. This may not be
* complete; we add calling codes case by case, as we find geographical mobile numbers or hear
Expand Down Expand Up @@ -787,20 +794,25 @@ public function getLengthOfGeographicalAreaCode(PhoneNumber $number): int
if ($metadata === null) {
return 0;
}

$countryCallingCode = $number->getCountryCode();


// If a country doesn't use a national prefix, and this number doesn't have an Italian leading
// zero, we assume it is a closed dialling plan with no area codes.
if (!$metadata->hasNationalPrefix() && !$number->isItalianLeadingZero()) {
// Note:this is our general assumption, but there are exceptions which are tracked in
// COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.
if (!$metadata->hasNationalPrefix() && !$number->isItalianLeadingZero() && !in_array($countryCallingCode, static::COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES)) {
return 0;
}

$type = $this->getNumberType($number);
$countryCallingCode = $number->getCountryCode();

if ($type === PhoneNumberType::MOBILE
// Note this is a rough heuristic; it doesn't cover Indonesia well, for example, where area
// codes are present for some mobile phones but not for others. We have no better way of
// representing this in the metadata at this point.
&& in_array($countryCallingCode, self::GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES)
&& in_array($countryCallingCode, static::GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES)
) {
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions src/data/PhoneNumberMetadata_FI.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
],
'fixedLine' => [
'pattern' => '(?:1[3-79][1-8]|[23568][1-8]\\d|9(?:00|[1-8]\\d))\\d{2,6}',
'pattern' => '1[35-7][1-8]\\d{3,6}|(?:1[49][1-8]|[23568][1-8]\\d|9(?:00|[1-8]\\d))\\d{2,6}',
'example' => '131234567',
'posLength' => [
5,
Expand Down Expand Up @@ -156,7 +156,7 @@
'pattern' => '(\\d)(\\d{4,9})',
'format' => '$1 $2',
'leadingDigitsPatterns' => [
'(?:1[3-79]|[2568])[1-8]|3(?:0[1-9]|[1-9])|9',
'(?:1[49]|[2568])[1-8]|3(?:0[1-9]|[1-9])|9',
],
'nationalPrefixFormattingRule' => '0$1',
'domesticCarrierCodeFormattingRule' => '',
Expand Down Expand Up @@ -203,7 +203,7 @@
'pattern' => '(\\d)(\\d{4,9})',
'format' => '$1 $2',
'leadingDigitsPatterns' => [
'(?:1[3-79]|[2568])[1-8]|3(?:0[1-9]|[1-9])|9',
'(?:1[49]|[2568])[1-8]|3(?:0[1-9]|[1-9])|9',
],
'nationalPrefixFormattingRule' => '0$1',
'domesticCarrierCodeFormattingRule' => '',
Expand Down
2 changes: 1 addition & 1 deletion src/data/PhoneNumberMetadata_GE.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
],
'mobile' => [
'pattern' => '5(?:(?:(?:0555|1(?:[17]77|555))[5-9]|757(?:7[7-9]|8[01]))\\d|22252[0-4])\\d\\d|(?:5(?:0(?:0(?:0\\d|11|22|3[0-6]|44|5[05]|77|88|9[09])|111|77\\d)|1(?:1(?:[03][01]|[124]\\d)|4\\d\\d)|[23]555|4(?:4\\d\\d|555)|5(?:[0157-9]\\d\\d|200)|6[89]\\d\\d|7(?:[0147-9]\\d\\d|5(?:00|[57]5))|8(?:0(?:[018]\\d|2[0-4])|5(?:55|8[89])|8(?:55|88))|9(?:090|[1-35-9]\\d\\d))|790\\d\\d)\\d{4}|5(?:0(?:0[17]0|505)|1(?:0[01]0|1(?:07|33|51))|2(?:0[02]0|2[25]2)|3(?:0[03]0|3[35]3)|(?:40[04]|900)0|5222)[0-4]\\d{3}',
'pattern' => '5(?:(?:(?:0555|1(?:[17]77|555))[5-9]|757(?:7[7-9]|8[01]))\\d|22252[0-4])\\d\\d|(?:5(?:0(?:0(?:0\\d|11|22|3[0-6]|44|5[05]|77|88|9[09])|111|22[02]|77\\d)|1(?:1(?:[03][01]|[124]\\d)|4\\d\\d)|[23]555|4(?:4\\d\\d|555)|5(?:[0157-9]\\d\\d|200)|6[89]\\d\\d|7(?:[0147-9]\\d\\d|5(?:00|[57]5))|8(?:0(?:[018]\\d|2[0-4])|5(?:55|8[89])|8(?:55|88))|9(?:090|[1-35-9]\\d\\d))|790\\d\\d)\\d{4}|5(?:0(?:0[17]0|505)|1(?:0[01]0|1(?:07|33|51))|2(?:0[02]0|2[25]2)|3(?:0[03]0|3[35]3)|(?:40[04]|900)0|5222)[0-4]\\d{3}',
'example' => '555123456',
],
'tollFree' => [
Expand Down
2 changes: 1 addition & 1 deletion src/data/PhoneNumberMetadata_GY.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'example' => '2201234',
],
'mobile' => [
'pattern' => '(?:510|6\\d\\d|7(?:[013]\\d|2[0-25-8]|4[0-29]|5[1-9]))\\d{4}',
'pattern' => '(?:510|6\\d\\d|7(?:[0135]\\d|2[0-8]|4[0-24-9]))\\d{4}',
'example' => '6091234',
],
'tollFree' => [
Expand Down
2 changes: 1 addition & 1 deletion src/data/PhoneNumberMetadata_HK.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
],
'mobile' => [
'pattern' => '(?:4(?:44[0-25-9]|6(?:1[0-7]|4[0-57-9]|6[0-4]))|5(?:73[0-6]|95[0-8])|6(?:26[013-8]|66[0-3])|70(?:7[1-8]|8[0-4])|848[0-35-9]|9(?:29[013-9]|39[01]|59[0-4]|899))\\d{4}|(?:4(?:4[0-35-8]|6[02357-9])|5(?:[1-59][0-46-9]|6[0-4689]|7[0-246-9])|6(?:0[1-9]|[13-59]\\d|[268][0-57-9]|7[0-79])|70[129]|84[0-29]|9(?:0[1-9]|1[02-9]|[2358][0-8]|[467]\\d))\\d{5}',
'pattern' => '(?:4(?:44[0-25-9]|6(?:1[0-7]|4[0-57-9]|6[0-4]))|5(?:73[0-6]|95[0-8])|6(?:26[013-8]|66[0-3])|70(?:7[1-8]|8[0-4])|848[0-35-9]|9(?:29[013-9]|39[01]|59[0-4]|899))\\d{4}|(?:4(?:4[0-35-8]|6[02357-9]|70)|5(?:[1-59][0-46-9]|6[0-4689]|7[0-246-9])|6(?:0[1-9]|[13-59]\\d|[268][0-57-9]|7[0-79])|70[1-39]|84[0-29]|9(?:0[1-9]|1[02-9]|[2358][0-8]|[467]\\d))\\d{5}',
'example' => '51234567',
'posLength' => [
8,
Expand Down
2 changes: 1 addition & 1 deletion src/data/PhoneNumberMetadata_IL.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
],
],
'voip' => [
'pattern' => '7(?:38(?:0\\d|5[0-29]|88)|8(?:33|55|77|81)\\d)\\d{4}|7(?:18|2[23]|3[237]|47|6[258]|7\\d|82|9[2-9])\\d{6}',
'pattern' => '7(?:38(?:0\\d|5[0-259]|88)|8(?:33|55|77|81)\\d)\\d{4}|7(?:18|2[23]|3[237]|47|6[258]|7\\d|82|9[2-9])\\d{6}',
'example' => '771234567',
'posLength' => [
9,
Expand Down
2 changes: 1 addition & 1 deletion src/data/PhoneNumberMetadata_MU.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
],
],
'mobile' => [
'pattern' => '5(?:4(?:2[1-389]|7[1-9])|87[15-8])\\d{4}|(?:5(?:2[5-9]|4[3-689]|[57]\\d|8[0-689]|9[0-8])|7(?:0[0-3]|3[013]))\\d{5}',
'pattern' => '5(?:4(?:2[1-389]|7[1-9])|87[15-8])\\d{4}|(?:5(?:2[5-9]|4[3-689]|[57]\\d|8[0-689]|9[0-8])|7(?:0[0-4]|3[013]))\\d{5}',
'example' => '52512345',
'posLength' => [
8,
Expand Down
4 changes: 2 additions & 2 deletions src/data/PhoneNumberMetadata_MX.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
],
],
'fixedLine' => [
'pattern' => '657[12]\\d{6}|(?:2(?:0[01]|2\\d|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[25-7][1-9]|3[1-8]|4\\d|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1346][1-9]|[27]\\d|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[0-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|[69]\\d|7[12]|8[1-8]))\\d{7}',
'pattern' => '657[12]\\d{6}|(?:2(?:0[01]|2\\d|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[25-7][1-9]|3[1-8]|4\\d|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[0-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1346][1-9]|[27]\\d|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[0-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|[69]\\d|7[12]|8[1-8]))\\d{7}',
'example' => '2001234567',
'posLengthLocal' => [
7,
8,
],
],
'mobile' => [
'pattern' => '657[12]\\d{6}|(?:2(?:2\\d|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[25-7][1-9]|3[1-8]|4\\d|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[1-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1346][1-9]|[27]\\d|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[0-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|[69]\\d|7[12]|8[1-8]))\\d{7}',
'pattern' => '657[12]\\d{6}|(?:2(?:2\\d|3[1-35-8]|4[13-9]|7[1-689]|8[1-578]|9[467])|3(?:1[1-79]|[2458][1-9]|3\\d|7[1-8]|9[1-5])|4(?:1[1-57-9]|[25-7][1-9]|3[1-8]|4\\d|8[1-35-9]|9[2-689])|5(?:[56]\\d|88|9[1-79])|6(?:1[2-68]|[2-4][1-9]|5[1-3689]|6[0-57-9]|7[1-7]|8[67]|9[4-8])|7(?:[1346][1-9]|[27]\\d|5[13-9]|8[1-69]|9[17])|8(?:1\\d|2[13-689]|3[1-6]|4[124-6]|6[1246-9]|7[0-378]|9[12479])|9(?:1[346-9]|2[1-4]|3[2-46-8]|5[1348]|[69]\\d|7[12]|8[1-8]))\\d{7}',
'example' => '2221234567',
'posLengthLocal' => [
7,
Expand Down
6 changes: 3 additions & 3 deletions src/data/PhoneNumberMetadata_TD.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'id' => 'TD',
'countryCode' => 235,
'generalDesc' => [
'pattern' => '(?:22|[69]\\d|77)\\d{6}',
'pattern' => '(?:22|[689]\\d|77)\\d{6}',
'posLength' => [
8,
],
Expand All @@ -20,7 +20,7 @@
'example' => '22501234',
],
'mobile' => [
'pattern' => '(?:6[0-689]|77|9\\d)\\d{6}',
'pattern' => '(?:[69]\\d|77|8[56])\\d{6}',
'example' => '63012345',
],
'tollFree' => [
Expand Down Expand Up @@ -75,7 +75,7 @@
'pattern' => '(\\d{2})(\\d{2})(\\d{2})(\\d{2})',
'format' => '$1 $2 $3 $4',
'leadingDigitsPatterns' => [
'[2679]',
'[26-9]',
],
'nationalPrefixFormattingRule' => '',
'domesticCarrierCodeFormattingRule' => '',
Expand Down
6 changes: 4 additions & 2 deletions src/data/ShortNumberMetadata_FI.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
],
],
'shortCode' => [
'pattern' => '11(?:2|6(?:00[06]|1(?:1[17]|23)))|75[12]\\d\\d',
'pattern' => '11(?:2|6(?:00[06]|1(?:1[17]|23)))|(?:1[235-8]\\d|75[12])\\d\\d',
'example' => '112',
],
'standardRate' => [
'pattern' => '1[235-8]\\d{3}',
'example' => '12000',
'posLength' => [
-1,
5,
],
],
'carrierSpecific' => [
Expand Down
3 changes: 3 additions & 0 deletions tests/core/PhoneNumberUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ public function testGetLengthOfGeographicalAreaCode(): void
// Italian numbers - there is no national prefix, but it still has an area code.
$this->assertEquals(2, $this->phoneUtil->getLengthOfGeographicalAreaCode(self::$itNumber));

// Mexico numbers - there is no national prefix, but it still has an area code.
$this->assertEquals(2, $this->phoneUtil->getLengthOfGeographicalAreaCode(self::$mxNumber1));

// Google Singapore. Singapore has no area code and no national prefix.
$this->assertEquals(0, $this->phoneUtil->getLengthOfGeographicalAreaCode(self::$sgNumber));

Expand Down

0 comments on commit a6e1029

Please sign in to comment.