Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MetadataSourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public function getMetadataForRegion(string $regionCode): PhoneMetadata;
/**
* Gets phone metadata for a non-geographical region.
*/
public function getMetadataForNonGeographicalRegion(int $countryCallingCode): PhoneMetadata;
public function getMetadataForNonGeographicalRegion(?int $countryCallingCode): PhoneMetadata;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the function declarations being changed?

Comment thread
Copilot marked this conversation as resolved.
Resolved
}
2 changes: 1 addition & 1 deletion src/MultiFileMetadataSourceImpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getMetadataForRegion(string $regionCode): PhoneMetadata
return $this->regionToMetadataMap[$regionCode];
}

public function getMetadataForNonGeographicalRegion(int $countryCallingCode): PhoneMetadata
public function getMetadataForNonGeographicalRegion(?int $countryCallingCode): PhoneMetadata
{
if (!isset($this->countryCodeToNonGeographicalMetadataMap[$countryCallingCode])) {
$this->loadMetadataFromFile($this->currentFilePrefix, PhoneNumberUtil::REGION_CODE_FOR_NON_GEO_ENTITY, $countryCallingCode);
Comment thread
Copilot marked this conversation as resolved.
Resolved
Expand Down
8 changes: 4 additions & 4 deletions src/PhoneNumberUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,13 +1059,13 @@ public function getNumberType(PhoneNumber $number): PhoneNumberType
return $this->getNumberTypeHelper($nationalSignificantNumber, $metadata);
}

protected function getMetadataForRegionOrCallingCode(int $countryCallingCode, ?string $regionCode): ?PhoneMetadata
protected function getMetadataForRegionOrCallingCode(?int $countryCallingCode, ?string $regionCode): ?PhoneMetadata
{
return static::REGION_CODE_FOR_NON_GEO_ENTITY === $regionCode ?
$this->getMetadataForNonGeographicalRegion($countryCallingCode) : $this->getMetadataForRegion($regionCode);
}

public function getMetadataForNonGeographicalRegion(int $countryCallingCode): ?PhoneMetadata
public function getMetadataForNonGeographicalRegion(?int $countryCallingCode): ?PhoneMetadata
{
if (!isset($this->countryCallingCodeToRegionCodeMap[$countryCallingCode])) {
return null;
Expand Down Expand Up @@ -1157,7 +1157,7 @@ public function getLengthOfNationalDestinationCode(PhoneNumber $number): int
*/
public function format(PhoneNumber $number, PhoneNumberFormat $numberFormat): string
{
if ($number->getNationalNumber() === '0' && $number->hasRawInput()) {
if (($number->getNationalNumber() === '0' || $number->getNationalNumber() === null) && $number->hasRawInput()) {
// Unparseable numbers that kept their raw input just use that, unless default country was
// specified and the format is E164. In that case, we prepend the raw input with the country
// code
Expand Down Expand Up @@ -1230,7 +1230,7 @@ protected function prefixNumberWithCountryCallingCode(int $countryCallingCode, P
/**
* Helper function to check the country calling code is valid.
*/
protected function hasValidCountryCallingCode(int $countryCallingCode): bool
protected function hasValidCountryCallingCode(?int $countryCallingCode): bool
{
return isset($this->countryCallingCodeToRegionCodeMap[$countryCallingCode]);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/core/PhoneNumberUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4165,4 +4165,13 @@ public function testIsMobileNumberPortableRegion(): void
self::assertFalse($this->phoneUtil->isMobileNumberPortableRegion(RegionCode::AE));
self::assertFalse($this->phoneUtil->isMobileNumberPortableRegion(RegionCode::BS));
}

public function testRawInput(): void
{
$numberA = new PhoneNumber();
$numberA->setRawInput('+1 650 253 00 00');

$responseString = $this->phoneUtil->format($numberA, PhoneNumberFormat::E164);
self::assertEquals('+1 650 253 00 00', $responseString);
}
}