| Conditions | 6 |
| Paths | 6 |
| Total Lines | 31 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 25 | public static function validate($cif) |
||
| 26 | { |
||
| 27 | $cifCodes = 'JABCDEFGHI'; |
||
| 28 | |||
| 29 | if (9 !== strlen($cif)) { |
||
| 30 | return false; |
||
| 31 | } |
||
| 32 | $cif = strtoupper(trim($cif)); |
||
| 33 | $sum = (string) Nif::getCifSum($cif); |
||
| 34 | |||
| 35 | $n = (10 - substr($sum, -1)) % 10; |
||
| 36 | |||
| 37 | if (preg_match('/^[ABCDEFGHJKNPQRSUVW]{1}/', $cif)) { |
||
| 38 | if (in_array($cif[0], array('A', 'B', 'E', 'H'))) { |
||
| 39 | // Numerico |
||
| 40 | return $cif[8] == $n; |
||
| 41 | } elseif (in_array($cif[0], array('K', 'P', 'Q', 'S'))) { |
||
| 42 | // Letras |
||
| 43 | return $cif[8] == $cifCodes[$n]; |
||
| 44 | } else { |
||
| 45 | // Alfanumérico |
||
| 46 | if (is_numeric($cif[8])) { |
||
| 47 | return $cif[8] == $n; |
||
| 48 | } else { |
||
| 49 | return $cif[8] == $cifCodes[$n]; |
||
| 50 | } |
||
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | return false; |
||
| 55 | } |
||
| 56 | } |
||
| 57 |