| Conditions | 5 |
| Paths | 5 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 21 | public static function validate($creditCard) |
||
| 22 | { |
||
| 23 | if (trim($creditCard) === '') { |
||
| 24 | return false; |
||
| 25 | } |
||
| 26 | |||
| 27 | //longueur de la chaine $creditCard |
||
| 28 | $length = strlen($creditCard); |
||
| 29 | |||
| 30 | //resultat de l'addition de tous les chiffres |
||
| 31 | $tot = 0; |
||
| 32 | for ($i = $length - 1; $i >= 0; --$i) { |
||
| 33 | $digit = substr($creditCard, $i, 1); |
||
| 34 | |||
| 35 | if ((($length - $i) % 2) == 0) { |
||
| 36 | $digit = $digit * 2; |
||
| 37 | if ($digit > 9) { |
||
| 38 | $digit = $digit - 9; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | $tot += (int) $digit; |
||
| 42 | } |
||
| 43 | |||
| 44 | return ($tot % 10) == 0; |
||
| 45 | } |
||
| 46 | } |
||
| 47 |