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