| Conditions | 6 |
| Paths | 10 |
| Total Lines | 23 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 20 | public static function check($luhn, $length, $unDecorate = true, $hyphens = []) |
||
| 21 | { |
||
| 22 | $luhn = $unDecorate ? self::unDecorate($luhn, $hyphens) : $luhn; |
||
| 23 | if (strlen($luhn) != $length) { |
||
| 24 | return false; |
||
| 25 | } |
||
| 26 | $expr = sprintf('/\\d{%d}/i', $length); |
||
| 27 | if (!preg_match($expr, $luhn)) { |
||
| 28 | return false; |
||
| 29 | } |
||
| 30 | $check = 0; |
||
| 31 | for ($i = 0; $i < $length; $i += 2) { |
||
| 32 | if ($length % 2 == 0) { |
||
| 33 | $check += 3 * substr($luhn, $i, 1); |
||
| 34 | $check += (int) substr($luhn, $i + 1, 1); |
||
| 35 | } else { |
||
| 36 | $check += (int) substr($luhn, $i, 1); |
||
| 37 | $check += 3 * substr($luhn, $i + 1, 1); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | return $check % 10 == 0; |
||
| 42 | } |
||
| 43 | |||
| 61 |