Total Complexity | 4 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
17 | class Email implements RuleValidateInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var array Rule properties |
||
21 | */ |
||
22 | public static $config = [ |
||
23 | 'class' => 'Email', |
||
24 | 'full_class' => __CLASS__, |
||
25 | 'alias' => ['email', 'mail', 'e@'], |
||
26 | 'args_count' => 0, |
||
27 | 'args_type' => [], |
||
28 | 'has_validate' => true, |
||
29 | //'has_sanitize' => false |
||
30 | ]; |
||
31 | |||
32 | /** |
||
33 | * @var string Error message |
||
34 | */ |
||
35 | private $message = ''; |
||
36 | |||
37 | /** |
||
38 | * Validate. |
||
39 | * |
||
40 | * @return bool |
||
41 | */ |
||
42 | 25 | public function validate(): bool |
|
43 | { |
||
44 | 25 | $args = func_get_args(); |
|
45 | |||
46 | 25 | return $this->concreteValidate($args[0]); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Concrete validate. |
||
51 | * |
||
52 | * @param string $received |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | 25 | private function concreteValidate(string $received): bool |
|
57 | { |
||
58 | 25 | if (!filter_var($received, FILTER_VALIDATE_EMAIL)) { |
|
59 | 18 | $this->message = "Received string is an invalid e-mail address"; |
|
60 | 18 | return true; |
|
61 | } |
||
62 | |||
63 | 7 | return false; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Return error message. |
||
68 | * |
||
69 | * @return string Error message |
||
70 | */ |
||
71 | 18 | public function getMessage(): string |
|
74 | } |
||
75 | } |
||
76 |