Conditions | 5 |
Paths | 7 |
Total Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
18 | public function validateAttribute($model, $attribute) |
||
19 | { |
||
20 | $phoneUtil = PhoneNumberUtil::getInstance(); |
||
21 | |||
22 | $value = $model->{$attribute}; |
||
23 | |||
24 | try { |
||
25 | $number = $phoneUtil->parse($value, $this->country); |
||
26 | |||
27 | if (!$phoneUtil->isValidNumber($number)) { |
||
28 | return $this->addError($model, $attribute, 'The given number is invalid.'); |
||
29 | } |
||
30 | |||
31 | // refactor the phone number |
||
32 | if ($number && $this->autoFormat) { |
||
33 | $model->{$attribute} = $phoneUtil->format($number, $this->autoFormatFormat); |
||
34 | } |
||
35 | |||
36 | } catch (NumberParseException $exception) { |
||
37 | $this->addError($model, $attribute, 'Invalid Phone Number, ensure the correct country code is available.'); |
||
38 | } |
||
39 | } |
||
40 | } |