Skip to content

Commit

Permalink
Merge 9ba021e into fda8a51
Browse files Browse the repository at this point in the history
  • Loading branch information
giggsey committed Aug 13, 2020
2 parents fda8a51 + 9ba021e commit f619057
Show file tree
Hide file tree
Showing 30 changed files with 606 additions and 304 deletions.
2 changes: 1 addition & 1 deletion METADATA-VERSION.txt
Expand Up @@ -2,4 +2,4 @@
# It can be a commit, branch or tag of the https://github.com/google/libphonenumber project
#
# For more information, look at the phing tasks in build.xml
v8.12.7
v8.12.8
14 changes: 10 additions & 4 deletions build/BuildMetadataFromXml.php
Expand Up @@ -190,8 +190,11 @@ public static function getNationalPrefixFormattingRuleFromElement(\DOMElement $e
{
$nationalPrefixFormattingRule = $element->getAttribute(self::NATIONAL_PREFIX_FORMATTING_RULE);
// Replace $NP with national prefix and $FG with the first group ($1).
$nationalPrefixFormattingRule = \str_replace(array('$NP', '$FG'), array($nationalPrefix, '$1'),
$nationalPrefixFormattingRule);
$nationalPrefixFormattingRule = \str_replace(
array('$NP', '$FG'),
array($nationalPrefix, '$1'),
$nationalPrefixFormattingRule
);
return $nationalPrefixFormattingRule;
}

Expand Down Expand Up @@ -324,8 +327,11 @@ public static function getDomesticCarrierCodeFormattingRuleFromElement(\DOMEleme
{
$carrierCodeFormattingRule = $element->getAttribute(self::CARRIER_CODE_FORMATTING_RULE);
// Replace $FG with the first group ($1) and $NP with the national prefix.
$carrierCodeFormattingRule = \str_replace(array('$NP', '$FG'), array($nationalPrefix, '$1'),
$carrierCodeFormattingRule);
$carrierCodeFormattingRule = \str_replace(
array('$NP', '$FG'),
array($nationalPrefix, '$1'),
$carrierCodeFormattingRule
);
return $carrierCodeFormattingRule;
}

Expand Down
18 changes: 9 additions & 9 deletions build/BuildMetadataPHPFromXml.php
Expand Up @@ -98,21 +98,21 @@ private function writeCountryCallingCodeMappingToFile($countryCodeToRegionCodeMa
if ($hasRegionCodes && $hasCountryCodes) {
$data .= self::MAP_COMMENT . PHP_EOL;
$data .= " public static \${$variableName} = " . \var_export(
$countryCodeToRegionCodeMap,
true
) . ';' . PHP_EOL;
$countryCodeToRegionCodeMap,
true
) . ';' . PHP_EOL;
} elseif ($hasCountryCodes) {
$data .= self::COUNTRY_CODE_SET_COMMENT . PHP_EOL;
$data .= " public static \${$variableName} = " . \var_export(
\array_keys($countryCodeToRegionCodeMap),
true
) . ';' . PHP_EOL;
\array_keys($countryCodeToRegionCodeMap),
true
) . ';' . PHP_EOL;
} else {
$data .= self::REGION_CODE_SET_COMMENT . PHP_EOL;
$data .= " public static \${$variableName} = " . \var_export(
$countryCodeToRegionCodeMap[0],
true
) . ';' . PHP_EOL;
$countryCodeToRegionCodeMap[0],
true
) . ';' . PHP_EOL;
}

$data .= PHP_EOL .
Expand Down
6 changes: 4 additions & 2 deletions build/MetadataFilter.php
Expand Up @@ -290,8 +290,10 @@ public function filterMetadata(PhoneMetadata $metadata)
}

if ($metadata->hasNoInternationalDialling()) {
$metadata->setNoInternationalDialling($this->getFiltered('noInternationalDialling',
$metadata->getNoInternationalDialling()));
$metadata->setNoInternationalDialling($this->getFiltered(
'noInternationalDialling',
$metadata->getNoInternationalDialling()
));
}

if ($this->shouldDrop('preferredInternationalPrefix')) {
Expand Down
19 changes: 13 additions & 6 deletions src/AsYouTypeFormatter.php
Expand Up @@ -239,8 +239,10 @@ private function maybeCreateNewTemplate()
}
if ($this->createFormattingTemplate($numberFormat)) {
$this->currentFormattingPattern = $pattern;
$nationalPrefixSeparatorsMatcher = new Matcher(self::$nationalPrefixSeparatorsPattern,
$numberFormat->getNationalPrefixFormattingRule());
$nationalPrefixSeparatorsMatcher = new Matcher(
self::$nationalPrefixSeparatorsPattern,
$numberFormat->getNationalPrefixFormattingRule()
);
$this->shouldAddSpaceAfterNationalPrefix = $nationalPrefixSeparatorsMatcher->find();
// With a new formatting template, the matched position using the old template
// needs to be reset.
Expand Down Expand Up @@ -272,7 +274,8 @@ private function getAvailableFormats($leadingDigits)
// prefix.
if ($this->extractedNationalPrefix !== ''
&& PhoneNumberUtil::formattingRuleHasFirstGroupOnly(
$format->getNationalPrefixFormattingRule())
$format->getNationalPrefixFormattingRule()
)
&& !$format->getNationalPrefixOptionalWhenFormatting()
&& !$format->hasDomesticCarrierCodeFormattingRule()) {
// If it is a national number that had a national prefix, any rules that aren't valid with a
Expand All @@ -285,7 +288,8 @@ private function getAvailableFormats($leadingDigits)
if ($this->extractedNationalPrefix === ''
&& !$this->isCompleteNumber
&& !PhoneNumberUtil::formattingRuleHasFirstGroupOnly(
$format->getNationalPrefixFormattingRule())
$format->getNationalPrefixFormattingRule()
)
&& !$format->getNationalPrefixOptionalWhenFormatting()) {
// This number was entered without a national prefix, and this formatting rule requires one,
// so we discard it.
Expand Down Expand Up @@ -480,6 +484,7 @@ private function inputDigitWithOptionToRememberPosition($nextChar, $rememberPosi
return $this->attemptToChooseFormattingPattern();
}
// fall through
// no break
default:
if ($this->isExpectingCountryCallingCode) {
if ($this->attemptToExtractCountryCallingCode()) {
Expand Down Expand Up @@ -820,8 +825,10 @@ private function inputDigitHelper($nextChar)
$digitMatcher = new Matcher(self::$digitPattern, $this->formattingTemplate);
if ($digitMatcher->find($this->lastMatchPosition)) {
$tempTemplate = $digitMatcher->replaceFirst($nextChar);
$this->formattingTemplate = $tempTemplate . \mb_substr($this->formattingTemplate, \mb_strlen($tempTemplate,
'UTF-8'), null, 'UTF-8');
$this->formattingTemplate = $tempTemplate . \mb_substr($this->formattingTemplate, \mb_strlen(
$tempTemplate,
'UTF-8'
), null, 'UTF-8');
$this->lastMatchPosition = $digitMatcher->start();
return \mb_substr($this->formattingTemplate, 0, $this->lastMatchPosition + 1);
}
Expand Down
13 changes: 10 additions & 3 deletions src/Leniency/ExactGrouping.php
Expand Up @@ -36,11 +36,18 @@ public static function verify(PhoneNumber $number, $candidate, PhoneNumberUtil $
return false;
}

return PhoneNumberMatcher::checkNumberGroupingIsValid($number, $candidate, $util,
return PhoneNumberMatcher::checkNumberGroupingIsValid(
$number,
$candidate,
$util,
function (PhoneNumberUtil $util, PhoneNumber $number, $normalizedCandidate, $expectedNumberGroups) {
return PhoneNumberMatcher::allNumberGroupsAreExactlyPresent(
$util, $number, $normalizedCandidate, $expectedNumberGroups
$util,
$number,
$normalizedCandidate,
$expectedNumberGroups
);
});
}
);
}
}
12 changes: 9 additions & 3 deletions src/Leniency/StrictGrouping.php
Expand Up @@ -38,11 +38,17 @@ public static function verify(PhoneNumber $number, $candidate, PhoneNumberUtil $
}

return PhoneNumberMatcher::checkNumberGroupingIsValid(
$number, $candidate, $util,
$number,
$candidate,
$util,
function (PhoneNumberUtil $util, PhoneNumber $number, $normalizedCandidate, $expectedNumberGroups) {
return PhoneNumberMatcher::allNumberGroupsRemainGrouped(
$util, $number, $normalizedCandidate, $expectedNumberGroups
$util,
$number,
$normalizedCandidate,
$expectedNumberGroups
);
});
}
);
}
}
37 changes: 25 additions & 12 deletions src/PhoneNumberMatcher.php
Expand Up @@ -422,8 +422,10 @@ protected function extractInnerMatch($candidate, $offset)
while ($groupMatcher->find() && $this->maxTries > 0) {
if ($isFirstMatch) {
// We should handle any group before this one too.
$group = static::trimAfterFirstMatch(PhoneNumberUtil::$UNWANTED_END_CHAR_PATTERN,
\mb_substr($candidate, 0, $groupMatcher->start()));
$group = static::trimAfterFirstMatch(
PhoneNumberUtil::$UNWANTED_END_CHAR_PATTERN,
\mb_substr($candidate, 0, $groupMatcher->start())
);

$match = $this->parseAndVerify($group, $offset);
if ($match !== null) {
Expand All @@ -432,8 +434,10 @@ protected function extractInnerMatch($candidate, $offset)
$this->maxTries--;
$isFirstMatch = false;
}
$group = static::trimAfterFirstMatch(PhoneNumberUtil::$UNWANTED_END_CHAR_PATTERN,
$groupMatcher->group(1));
$group = static::trimAfterFirstMatch(
PhoneNumberUtil::$UNWANTED_END_CHAR_PATTERN,
$groupMatcher->group(1)
);
$match = $this->parseAndVerify($group, $offset + $groupMatcher->start(1));
if ($match !== null) {
return $match;
Expand Down Expand Up @@ -590,8 +594,10 @@ public static function allNumberGroupsAreExactlyPresent(
// We use contains and not equals, since the national significant number may be present with
// a prefix such as a national number prefix, or the country code itself.
if (\count($candidateGroups) == 1
|| \mb_strpos($candidateGroups[$candidateNumberGroupIndex],
$util->getNationalSignificantNumber($number)) !== false
|| \mb_strpos(
$candidateGroups[$candidateNumberGroupIndex],
$util->getNationalSignificantNumber($number)
) !== false
) {
return true;
}
Expand All @@ -609,8 +615,10 @@ public static function allNumberGroupsAreExactlyPresent(
// Now check the first group. There may be a national prefix at the start, so we only check
// that the candidate group ends with the formatted number group.
return ($candidateNumberGroupIndex >= 0
&& \mb_substr($candidateGroups[$candidateNumberGroupIndex],
-\mb_strlen($formattedNumberGroups[0])) == $formattedNumberGroups[0]);
&& \mb_substr(
$candidateGroups[$candidateNumberGroupIndex],
-\mb_strlen($formattedNumberGroups[0])
) == $formattedNumberGroups[0]);
}

/**
Expand Down Expand Up @@ -644,8 +652,11 @@ protected static function getNationalNumberGroups(

// If a format is provided, we format the NSN only, and split that according to the separator.
$nationalSignificantNumber = $util->getNationalSignificantNumber($number);
return \explode('-', $util->formatNsnUsingPattern($nationalSignificantNumber, $formattingPattern,
PhoneNumberFormat::RFC3966));
return \explode('-', $util->formatNsnUsingPattern(
$nationalSignificantNumber,
$formattingPattern,
PhoneNumberFormat::RFC3966
));
}

/**
Expand Down Expand Up @@ -756,8 +767,10 @@ public static function containsOnlyValidXChars(PhoneNumber $number, $candidate,
if ($util->isNumberMatch($number, \mb_substr($candidate, $index)) != MatchType::NSN_MATCH) {
return false;
}
} elseif (!PhoneNumberUtil::normalizeDigitsOnly(\mb_substr($candidate,
$index)) == $number->getExtension()
} elseif (!PhoneNumberUtil::normalizeDigitsOnly(\mb_substr(
$candidate,
$index
)) == $number->getExtension()
) {
// This is the extension sign case, in which the 'x' or 'X' should always precede the
// extension number
Expand Down
36 changes: 25 additions & 11 deletions src/PhoneNumberUtil.php
Expand Up @@ -600,8 +600,10 @@ protected static function normalizeHelper($number, array $normalizationReplaceme
*/
public static function formattingRuleHasFirstGroupOnly($nationalPrefixFormattingRule)
{
$firstGroupOnlyPrefixPatternMatcher = new Matcher(static::FIRST_GROUP_ONLY_PREFIX_PATTERN,
$nationalPrefixFormattingRule);
$firstGroupOnlyPrefixPatternMatcher = new Matcher(
static::FIRST_GROUP_ONLY_PREFIX_PATTERN,
$nationalPrefixFormattingRule
);

return mb_strlen($nationalPrefixFormattingRule) === 0
|| $firstGroupOnlyPrefixPatternMatcher->matches();
Expand Down Expand Up @@ -1761,8 +1763,11 @@ protected function buildNationalNumberForParsing($numberToParse, &$nationalNumbe

$indexOfRfc3966Prefix = strpos($numberToParse, static::RFC3966_PREFIX);
$indexOfNationalNumber = ($indexOfRfc3966Prefix !== false) ? $indexOfRfc3966Prefix + strlen(static::RFC3966_PREFIX) : 0;
$nationalNumber .= substr($numberToParse, $indexOfNationalNumber,
$indexOfPhoneContext - $indexOfNationalNumber);
$nationalNumber .= substr(
$numberToParse,
$indexOfNationalNumber,
$indexOfPhoneContext - $indexOfNationalNumber
);
} else {
// Extract a possible number from the string passed in (this strips leading characters that
// could not be the start of a phone number.)
Expand Down Expand Up @@ -2145,7 +2150,10 @@ public function maybeStripNationalPrefixAndCarrierCode(&$number, PhoneMetadata $
// If the original number was viable, and the resultant number is not, we return.
if ($isViableOriginalNumber &&
!$this->matcherAPI->matchNationalNumber(
substr($number, $prefixMatcher->end()), $generalDesc, false)) {
substr($number, $prefixMatcher->end()),
$generalDesc,
false
)) {
return false;
}
if ($carrierCode !== null && $numOfGroups > 0 && $prefixMatcher->group($numOfGroups) !== null) {
Expand Down Expand Up @@ -2232,9 +2240,11 @@ protected function testNumberLength($number, PhoneMetadata $metadata, $type = Ph
// Note that when adding the possible lengths from mobile, we have to again check they
// aren't empty since if they are this indicates they are the same as the general desc and
// should be obtained from there.
$possibleLengths = array_merge($possibleLengths,
$possibleLengths = array_merge(
$possibleLengths,
(count($mobileDesc->getPossibleLength()) === 0)
? $metadata->getGeneralDesc()->getPossibleLength() : $mobileDesc->getPossibleLength());
? $metadata->getGeneralDesc()->getPossibleLength() : $mobileDesc->getPossibleLength()
);

// The current list is sorted; we need to merge in the new list and re-sort (duplicates
// are okay). Sorting isn't so expensive because the lists are very small.
Expand Down Expand Up @@ -2384,7 +2394,8 @@ public function formatNumberForMobileDialing(PhoneNumber $number, $regionCalling
} else {
$formattedNumber = $this->format($numberNoExt, PhoneNumberFormat::NATIONAL);
}
} elseif (($regionCode == static::REGION_CODE_FOR_NON_GEO_ENTITY ||
} elseif ((
$regionCode == static::REGION_CODE_FOR_NON_GEO_ENTITY ||
// MX fixed line and mobile numbers should always be formatted in international format,
// even when dialed within MX. For national format to work, a carrier code needs to be
// used, and the correct carrier code depends on if the caller and callee are from the
Expand All @@ -2397,7 +2408,7 @@ public function formatNumberForMobileDialing(PhoneNumber $number, $regionCalling
($regionCode === 'MX' || $regionCode === 'CL' || $regionCode === 'UZ')
&& $isFixedLineOrMobile
)
) && $this->canBeInternationallyDialled($numberNoExt)
) && $this->canBeInternationallyDialled($numberNoExt)
) {
$formattedNumber = $this->format($numberNoExt, PhoneNumberFormat::INTERNATIONAL);
} else {
Expand Down Expand Up @@ -3060,8 +3071,11 @@ public function formatByPattern(PhoneNumber $number, $numberFormat, array $userD
$nationalPrefix = $metadata->getNationalPrefix();
if (mb_strlen($nationalPrefix) > 0) {
// Replace $NP with national prefix and $FG with the first group ($1).
$nationalPrefixFormattingRule = str_replace(array(static::NP_STRING, static::FG_STRING),
array($nationalPrefix, '$1'), $nationalPrefixFormattingRule);
$nationalPrefixFormattingRule = str_replace(
array(static::NP_STRING, static::FG_STRING),
array($nationalPrefix, '$1'),
$nationalPrefixFormattingRule
);
$numFormatCopy->setNationalPrefixFormattingRule($nationalPrefixFormattingRule);
} else {
// We don't want to have a rule for how to format the national prefix if there isn't one.
Expand Down
3 changes: 2 additions & 1 deletion src/ShortNumberInfo.php
Expand Up @@ -246,7 +246,8 @@ protected function matchesEmergencyNumberHelper($number, $regionCode, $allowPref
$normalizedNumber = PhoneNumberUtil::normalizeDigitsOnly($number);
$emergencyDesc = $metadata->getEmergency();

$allowPrefixMatchForRegion = ($allowPrefixMatch
$allowPrefixMatchForRegion = (
$allowPrefixMatch
&& !in_array($regionCode, static::$regionsWhereEmergencyNumbersMustBeExact)
);

Expand Down
20 changes: 10 additions & 10 deletions src/carrier/data/en/226.php
Expand Up @@ -14,28 +14,28 @@
22601 => 'Onatel',
22602 => 'Onatel',
22607 => 'Orange',
22651 => 'Telmob',
22652 => 'Telmob',
22651 => 'Onatel',
22652 => 'Onatel',
22653 => 'Onatel',
22654 => 'Orange',
22655 => 'Orange',
22656 => 'Orange',
22657 => 'Orange',
22658 => 'Telecel Faso',
22660 => 'Telmob',
22661 => 'Telmob',
22662 => 'Telmob',
22663 => 'Telmob',
22660 => 'Onatel',
22661 => 'Onatel',
22662 => 'Onatel',
22663 => 'Onatel',
22664 => 'Orange',
22665 => 'Orange',
22666 => 'Orange',
22667 => 'Orange',
22668 => 'Telecel Faso',
22669 => 'Telecel Faso',
22670 => 'Telmob',
22671 => 'Telmob',
22672 => 'Telmob',
22673 => 'Telmob',
22670 => 'Onatel',
22671 => 'Onatel',
22672 => 'Onatel',
22673 => 'Onatel',
22674 => 'Orange',
22675 => 'Orange',
22676 => 'Orange',
Expand Down

0 comments on commit f619057

Please sign in to comment.