-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from maxmind/greg/phone-data
Add new phone outputs
- Loading branch information
Showing
8 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MaxMind\MinFraud\Model; | ||
|
||
/** | ||
* Model containing information about the billing or shipping phone number. | ||
*/ | ||
class Phone implements \JsonSerializable | ||
{ | ||
/** | ||
* @var string|null the two-character ISO 3166-1 country code for the | ||
* country associated with the phone number | ||
*/ | ||
public readonly ?string $country; | ||
|
||
/** | ||
* @var bool|null This is `true` if the phone number is a Voice over | ||
* Internet Protocol (VoIP) number allocated by a regulator. | ||
* It is `false` if the phone number is not a VoIP number | ||
* allocated by a regulator. It is `null` if a valid number | ||
* was not provided or if we do not have data for the number. | ||
*/ | ||
public readonly ?bool $isVoip; | ||
|
||
/** | ||
* @var string|null The name of the original network operator associated with | ||
* the phone number. This property does not reflect phone numbers | ||
* that have been ported from the original operator to another, | ||
* nor does it identify mobile virtual network operators. | ||
*/ | ||
public readonly ?string $networkOperator; | ||
|
||
/** | ||
* @var string|null One of the following values: `fixed` or `mobile`. Additional | ||
* values may be added in the future. | ||
*/ | ||
public readonly ?string $numberType; | ||
|
||
public function __construct(?array $response) | ||
{ | ||
$this->country = $response['country'] ?? null; | ||
$this->isVoip = $response['is_voip'] ?? null; | ||
$this->networkOperator = $response['network_operator'] ?? null; | ||
$this->numberType = $response['number_type'] ?? null; | ||
} | ||
|
||
public function jsonSerialize(): array | ||
{ | ||
$js = []; | ||
|
||
if ($this->country !== null) { | ||
$js['country'] = $this->country; | ||
} | ||
|
||
if ($this->isVoip !== null) { | ||
$js['is_voip'] = $this->isVoip; | ||
} | ||
|
||
if ($this->networkOperator !== null) { | ||
$js['network_operator'] = $this->networkOperator; | ||
} | ||
|
||
if ($this->numberType !== null) { | ||
$js['number_type'] = $this->numberType; | ||
} | ||
|
||
return $js; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MaxMind\Test\MinFraud\Model; | ||
|
||
use MaxMind\MinFraud\Model\Phone; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @coversNothing | ||
* | ||
* @internal | ||
*/ | ||
class PhoneTest extends TestCase | ||
{ | ||
public function testPhone(): void | ||
{ | ||
$array = [ | ||
'country' => 'US', | ||
'is_voip' => true, | ||
'network_operator' => 'Verizon/1', | ||
'number_type' => 'fixed', | ||
]; | ||
$phone = new Phone($array); | ||
|
||
$this->assertSame( | ||
$array['country'], | ||
$phone->country, | ||
'country' | ||
); | ||
|
||
$this->assertSame( | ||
$array['is_voip'], | ||
$phone->isVoip, | ||
'isVoip' | ||
); | ||
|
||
$this->assertSame( | ||
$array['network_operator'], | ||
$phone->networkOperator, | ||
'networkOperator' | ||
); | ||
|
||
$this->assertSame( | ||
$array['number_type'], | ||
$phone->numberType, | ||
'numberType' | ||
); | ||
|
||
$this->assertSame( | ||
$array, | ||
$phone->jsonSerialize(), | ||
'correctly implements JsonSerializable' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters