We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 5 |
| Paths | 3 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| 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 | 15 | || !filter_var($input, FILTER_VALIDATE_INT) |
|
| 20 | 15 | || strlen($input) != 11) { |
|
| 21 | 6 | return false; |
|
| 22 | } |
||
| 23 | |||
| 24 | 9 | $weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3]; |
|
| 25 | |||
| 26 | 9 | $targetControlNumber = $input[10]; |
|
| 27 | 9 | $calculateControlNumber = 0; |
|
| 28 | |||
| 29 | 9 | for ($i = 0; $i < 10; $i++) { |
|
| 30 | 9 | $calculateControlNumber += $input[$i] * $weights[$i]; |
|
| 31 | 9 | } |
|
| 32 | |||
| 33 | 9 | $calculateControlNumber = (10 - $calculateControlNumber % 10) % 10; |
|
| 34 | |||
| 35 | 9 | return $targetControlNumber == $calculateControlNumber; |
|
| 36 | } |
||
| 37 | } |
||
| 38 |