We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 4 |
| Paths | 4 |
| Total Lines | 23 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 23 | 11 | public function validate($input) |
|
| 24 | { |
||
| 25 | 11 | if (!is_scalar($input)) { |
|
| 26 | 2 | return false; |
|
| 27 | } |
||
| 28 | |||
| 29 | 9 | if (!preg_match('/^\d{10}$/', (string) $input)) { |
|
| 30 | 2 | return false; |
|
| 31 | } |
||
| 32 | |||
| 33 | 7 | $weights = [6, 5, 7, 2, 3, 4, 5, 6, 7]; |
|
| 34 | |||
| 35 | 7 | $targetControlNumber = $input[9]; |
|
| 36 | 7 | $calculateControlNumber = 0; |
|
| 37 | |||
| 38 | 7 | for ($i = 0; $i < 9; ++$i) { |
|
| 39 | 7 | $calculateControlNumber += $input[$i] * $weights[$i]; |
|
| 40 | 7 | } |
|
| 41 | |||
| 42 | 7 | $calculateControlNumber = $calculateControlNumber % 11; |
|
| 43 | |||
| 44 | 7 | return $targetControlNumber == $calculateControlNumber; |
|
| 45 | } |
||
| 46 | } |
||
| 47 |