From 096ef7ed0542c56fe5d4edfc544542c33f4af3f0 Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Mon, 18 Jul 2022 14:09:19 +0200 Subject: [PATCH] define allowed number types as class property --- src/ValueObject/Recipient.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ValueObject/Recipient.php b/src/ValueObject/Recipient.php index d387249..d32dde8 100644 --- a/src/ValueObject/Recipient.php +++ b/src/ValueObject/Recipient.php @@ -25,6 +25,14 @@ use libphonenumber\PhoneNumberUtil; class Recipient extends StringValueObject { + /** + * @var array + */ + protected $allowedNumberTypes = [ + PhoneNumberType::MOBILE, + PhoneNumberType::FIXED_LINE_OR_MOBILE + ]; + /** * @var string */ @@ -45,17 +53,14 @@ class Recipient extends StringValueObject $phoneUtil = $this->getPhoneNumberUtil(); $phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode)); - $number = $phoneUtil->format($phoneNumber, PhoneNumberFormat::E164); + $number = $phoneUtil->format( $phoneNumber, PhoneNumberFormat::E164 ); if (false === $phoneUtil->isValidNumber($phoneNumber)) { throw new RecipientException(ExceptionMessages::INVALID_RECIPIENT_PHONE); } elseif ( false === in_array( $phoneUtil->getNumberType($phoneNumber), - [ - PhoneNumberType::MOBILE, - PhoneNumberType::FIXED_LINE_OR_MOBILE - ] + $this->allowedNumberTypes ) ) { throw new RecipientException( ExceptionMessages::NOT_A_MOBILE_NUMBER);