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 | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | 36 | public function isValid($input): bool |
|
| 28 | { |
||
| 29 | 36 | if (!is_scalar($input)) { |
|
| 30 | 2 | return false; |
|
| 31 | } |
||
| 32 | |||
| 33 | 34 | $digits = preg_replace('/\D/', '', $input); |
|
| 34 | 34 | if (11 != mb_strlen($digits) || preg_match("/^{$digits[0]}{11}$/", $digits)) { |
|
| 35 | 13 | return false; |
|
| 36 | } |
||
| 37 | |||
| 38 | 21 | $multipliers = [3, 2, 9, 8, 7, 6, 5, 4, 3, 2]; |
|
| 39 | |||
| 40 | 21 | $summation = 0; |
|
| 41 | 21 | for ($position = 0; $position < 10; ++$position) { |
|
| 42 | 21 | $summation += $digits[$position] * $multipliers[$position]; |
|
| 43 | } |
||
| 44 | |||
| 45 | 21 | $checkDigit = (int) $digits[10]; |
|
| 46 | |||
| 47 | 21 | $modulo = $summation % 11; |
|
| 48 | |||
| 49 | 21 | return $checkDigit === (($modulo < 2) ? 0 : 11 - $modulo); |
|
| 50 | } |
||
| 52 |