| Total Complexity | 4 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class ValidPhoneNumber implements Rule |
||
| 10 | { |
||
| 11 | public function __construct(protected ?string $code = null) |
||
| 12 | { |
||
| 13 | } |
||
| 14 | /** |
||
| 15 | * Check phone number is valid. |
||
| 16 | * |
||
| 17 | * @param string $attribute |
||
| 18 | * @param mixed $value |
||
| 19 | * @return bool |
||
| 20 | */ |
||
| 21 | public function passes($attribute, $value) |
||
| 22 | { |
||
| 23 | if (is_string($this->code)) { |
||
| 24 | $passes = (new CountryPhoneCallback($value, $this->code))->callPhoneValidator(); |
||
| 25 | return collect($passes)->some(fn ($passe) => $passe); |
||
|
|
|||
| 26 | } |
||
| 27 | return preg_match('/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/', $value); |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get the validation error message. |
||
| 32 | * |
||
| 33 | * @return string |
||
| 34 | */ |
||
| 35 | public function message() |
||
| 38 | } |
||
| 39 | } |
||
| 40 |