Total Complexity | 4 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
17 | class Number extends AbstractNumber implements RuleSanitizeInterface, RuleValidateInterface |
||
18 | { |
||
19 | /** |
||
20 | * @var array Rule properties |
||
21 | */ |
||
22 | public static $config = [ |
||
23 | 'full_class' => __CLASS__, |
||
24 | 'alias' => ['number', 'num', 'n'], |
||
25 | 'args_count' => 0, |
||
26 | 'args_type' => [] |
||
27 | ]; |
||
28 | |||
29 | /** |
||
30 | * @var string Error message |
||
31 | */ |
||
32 | private $message = ''; |
||
33 | |||
34 | /** |
||
35 | * Validate. |
||
36 | * |
||
37 | * @return bool |
||
38 | */ |
||
39 | 16 | public function validate(): bool |
|
40 | { |
||
41 | 16 | $args = \func_get_args(); |
|
42 | |||
43 | 16 | return $this->concreteValidate($args[0]); |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * Concrete validate. |
||
48 | * |
||
49 | * @param int|float $received |
||
50 | * |
||
51 | * @return bool |
||
52 | */ |
||
53 | 16 | private function concreteValidate($received): bool |
|
54 | { |
||
55 | 16 | if (!\is_numeric($received)) { |
|
|
|||
56 | 8 | $this->message = "Received value is not a number"; |
|
57 | 8 | return true; |
|
58 | } |
||
59 | |||
60 | 8 | return false; |
|
61 | } |
||
62 | |||
63 | /** |
||
64 | * Return error message. |
||
65 | * |
||
66 | * @return string Error message |
||
67 | */ |
||
68 | 1 | public function getMessage(): string |
|
71 | } |
||
72 | } |
||
73 |