define allowed number types as class property
This commit is contained in:
parent
dc0b680776
commit
096ef7ed05
@ -25,6 +25,14 @@ use libphonenumber\PhoneNumberUtil;
|
|||||||
|
|
||||||
class Recipient extends StringValueObject
|
class Recipient extends StringValueObject
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
protected $allowedNumberTypes = [
|
||||||
|
PhoneNumberType::MOBILE,
|
||||||
|
PhoneNumberType::FIXED_LINE_OR_MOBILE
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
@ -45,17 +53,14 @@ class Recipient extends StringValueObject
|
|||||||
$phoneUtil = $this->getPhoneNumberUtil();
|
$phoneUtil = $this->getPhoneNumberUtil();
|
||||||
|
|
||||||
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
$phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode));
|
||||||
$number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164);
|
$number = $phoneUtil->format( $phoneNumber, PhoneNumberFormat::E164 );
|
||||||
|
|
||||||
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
if (false === $phoneUtil->isValidNumber($phoneNumber)) {
|
||||||
throw new RecipientException(ExceptionMessages::INVALID_RECIPIENT_PHONE);
|
throw new RecipientException(ExceptionMessages::INVALID_RECIPIENT_PHONE);
|
||||||
} elseif (
|
} elseif (
|
||||||
false === in_array(
|
false === in_array(
|
||||||
$phoneUtil->getNumberType($phoneNumber),
|
$phoneUtil->getNumberType($phoneNumber),
|
||||||
[
|
$this->allowedNumberTypes
|
||||||
PhoneNumberType::MOBILE,
|
|
||||||
PhoneNumberType::FIXED_LINE_OR_MOBILE
|
|
||||||
]
|
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
throw new RecipientException( ExceptionMessages::NOT_A_MOBILE_NUMBER);
|
throw new RecipientException( ExceptionMessages::NOT_A_MOBILE_NUMBER);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user