We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 6 |
| Paths | 6 |
| Total Lines | 24 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | 31 | public function validate($input) |
|
| 26 | { |
||
| 27 | 31 | if (!is_scalar($input)) { |
|
| 28 | 2 | return false; |
|
| 29 | } |
||
| 30 | |||
| 31 | 29 | $digits = preg_replace('/\D/', '', $input); |
|
| 32 | 29 | if (mb_strlen($digits) != 11 || preg_match("/^{$digits[0]}{11}$/", $digits)) { |
|
| 33 | 11 | return false; |
|
| 34 | } |
||
| 35 | |||
| 36 | 18 | $multipliers = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; |
|
| 37 | |||
| 38 | 18 | $summation = 0; |
|
| 39 | 18 | for ($position = 0; $position < 10; ++$position) { |
|
| 40 | 18 | $summation += $digits[$position] * $multipliers[$position]; |
|
| 41 | } |
||
| 42 | |||
| 43 | 18 | $checkDigit = (int) $digits[10]; |
|
| 44 | |||
| 45 | 18 | $modulo = $summation % 11; |
|
| 46 | |||
| 47 | 18 | return $checkDigit === (($modulo < 2) ? 0 : 11 - $modulo); |
|
| 48 | } |
||
| 49 | } |
||
| 50 |