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