Skip to content

Commit

Permalink
Check for unsure type when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
Propaganistas committed Mar 8, 2018
1 parent d816904 commit 79b7901
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Str;
use JsonSerializable;
use libphonenumber\PhoneNumberFormat;
use libphonenumber\PhoneNumberType;
use libphonenumber\PhoneNumberUtil;
use Propaganistas\LaravelPhone\Exceptions\NumberFormatException;
use Propaganistas\LaravelPhone\Exceptions\CountryCodeException;
Expand Down Expand Up @@ -294,6 +295,11 @@ public function isOfType($type)
{
$types = static::parseTypes($type);

// Add the unsure type when applicable.
if (array_intersect([PhoneNumberType::FIXED_LINE, PhoneNumberType::MOBILE], $types)) {
$types[] = PhoneNumberType::FIXED_LINE_OR_MOBILE;
}

return in_array($this->getType(true), $types, true);
}

Expand Down
10 changes: 10 additions & 0 deletions tests/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ public function it_can_check_the_type()
$this->assertTrue($object->isOfType(PhoneNumberType::MOBILE));
}

/* @test */
public function it_adds_the_unsure_type()
{
// This number is of type FIXED_LINE_OR_MOBILE.
// Without the unsure type, the following check would fail.
$object = new PhoneNumber('8590332334');
$object = $object->ofCountry('IN');
$this->assertTrue($object->isOfType('fixed_line'));
}

/** @test */
public function it_can_verify_types()
{
Expand Down

0 comments on commit 79b7901

Please sign in to comment.