Conditions | 4 |
Paths | 4 |
Total Lines | 17 |
Code Lines | 10 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
27 | public function sanitizePhoneNumber(string $number, string $defaultRegion = 'NL'): string |
||
28 | { |
||
29 | $util = PhoneNumberUtil::getInstance(); |
||
30 | $region = strpos($number, '+') === false ? $defaultRegion : 'ZZ'; |
||
31 | $proto = $util->parse($number, $region); |
||
32 | |||
33 | if ( |
||
34 | $util->isViablePhoneNumber($number) === false |
||
35 | || $util->isValidNumber($proto) === false |
||
36 | ) { |
||
37 | throw new NumberParseException( |
||
38 | NumberParseException::NOT_A_NUMBER, |
||
39 | "The string supplied does not seem to be a valid phone number.", |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | return '00' . $proto->getCountryCode() . $proto->getNationalNumber(); |
||
44 | } |
||
46 |