We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 5 |
| Paths | 5 |
| Total Lines | 27 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 5 |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | 15 | public function validate($input) |
|
| 17 | { |
||
| 18 | 15 | if (!is_numeric($input)) { |
|
| 19 | 2 | return false; |
|
| 20 | } |
||
| 21 | |||
| 22 | 13 | if (!filter_var($input, FILTER_VALIDATE_INT)) { |
|
| 23 | 2 | return false; |
|
| 24 | } |
||
| 25 | |||
| 26 | 11 | if (strlen($input) != 11) { |
|
| 27 | 2 | return false; |
|
| 28 | } |
||
| 29 | |||
| 30 | 9 | $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]; |
|
| 31 | |||
| 32 | 9 | $targetControlNumber = $input[10]; |
|
| 33 | 9 | $calculateControlNumber = 0; |
|
| 34 | |||
| 35 | 9 | for ($i = 0; $i < 10; $i++) { |
|
| 36 | 9 | $calculateControlNumber += $input[$i] * $weights[$i]; |
|
| 37 | 9 | } |
|
| 38 | |||
| 39 | 9 | $calculateControlNumber = (10 - $calculateControlNumber % 10) % 10; |
|
| 40 | |||
| 41 | 9 | return $targetControlNumber == $calculateControlNumber; |
|
| 42 | } |
||
| 43 | } |
||
| 44 |