Total Complexity | 6 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
8 | class Gtin implements Rule |
||
9 | { |
||
10 | protected string $message; |
||
11 | |||
12 | public function __construct() |
||
14 | // |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * Determine if the validation rule passes. |
||
19 | * |
||
20 | * @param string $attribute |
||
21 | * @param mixed $value |
||
22 | * @return bool |
||
23 | */ |
||
24 | public function passes($attribute, $value) |
||
25 | { |
||
26 | // GTIN is between 8 and 14 characters long |
||
27 | if (! GtinValidator::length($value)) { |
||
28 | $this->message = 'The GTIN must be between 8 and 14 characters long'; |
||
29 | |||
30 | return false; |
||
31 | } |
||
32 | |||
33 | // GTIN is a number |
||
34 | if (! GtinValidator::integer($value)) { |
||
35 | $this->message = 'The GTIN must be an integer'; |
||
36 | |||
37 | return false; |
||
38 | } |
||
39 | |||
40 | if (! GtinValidator::inspect($value)) { |
||
41 | $this->message = "The GTIN value {$value} does not pass algorithmic inspection."; |
||
42 | |||
43 | return false; |
||
44 | } |
||
45 | |||
46 | return true; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Get the validation error message. |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function message() |
||
57 | } |
||
58 | } |
||
59 |