Skip to content

Commit

Permalink
bugfix (fixes #250)
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas committed Apr 24, 2024
1 parent b7461f0 commit 45f1f3d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function getCountry(): ?string
continue;
}

if (PhoneNumberUtil::getInstance()->isValidNumberForRegion($libPhoneObject, $country)) {
if (PhoneNumberUtil::getInstance()->isValidNumberForRegion($libPhoneObject, $country ?? 'ZZ')) {
return PhoneNumberUtil::getInstance()->getRegionCodeForNumber($libPhoneObject);
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public function isValid(): bool

return PhoneNumberUtil::getInstance()->isValidNumberForRegion(
$this->toLibPhoneObject(),
$this->getCountry(),
$this->getCountry() ?? 'ZZ',
);
} catch (NumberParseException $e) {
return false;
Expand Down
14 changes: 14 additions & 0 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ public function it_validates_with_custom_country_field_taking_precedence_over_im
#[Test]
public function it_validates_in_international_mode()
{
$this->assertTrue($this->validate(
['field' => '+3212345678'],
['field' => (new Phone)->international()]
)->passes());

$this->assertFalse($this->validate(
['field' => '+3212345678'],
['field' => (new Phone)->country('NL')]
Expand All @@ -180,6 +185,15 @@ public function it_validates_in_international_mode()
)->passes());
}

#[Test]
public function it_validates_non_parseable_international_looking_numbers()
{
$this->assertFalse($this->validate(
['field' => '+12345678901234'],
['field' => (new Phone)->international()]
)->passes());
}

#[Test]
public function it_validates_in_lenient_mode()
{
Expand Down

0 comments on commit 45f1f3d

Please sign in to comment.