Total Complexity | 5 |
Total Lines | 27 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | class ValidCartNumberIran implements Rule |
||
8 | { |
||
9 | /** |
||
10 | * Check cart number is valid. |
||
11 | */ |
||
12 | public function passes($attribute, $value): bool |
||
13 | { |
||
14 | $cardToArr = str_split($value); |
||
15 | $cardTotal = 0; |
||
16 | for ($i = 0; $i < 16; $i++) { |
||
17 | $c = (int) $cardToArr[$i]; |
||
18 | if ($i % 2 === 0) { |
||
19 | $cardTotal += (($c * 2 > 9) ? ($c * 2) - 9 : ($c * 2)); |
||
20 | } else { |
||
21 | $cardTotal += $c; |
||
22 | } |
||
23 | } |
||
24 | |||
25 | return $cardTotal % 10 === 0; |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Get the validation error message. |
||
30 | */ |
||
31 | public function message(): string |
||
34 | } |
||
35 | } |
||
36 |