| Conditions | 6 |
| Paths | 11 |
| Total Lines | 25 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | 103 | public static function calculateCheckDigit($number) |
|
| 29 | { |
||
| 30 | 103 | if (!ctype_digit($number)) { |
|
| 31 | 6 | throw new Exception\InvalidStructureException( |
|
| 32 | 6 | "Number can only contain numerical characters, found: $number" |
|
| 33 | ); |
||
| 34 | } |
||
| 35 | |||
| 36 | 97 | $weight = 2; |
|
| 37 | 97 | $sum = 0; |
|
| 38 | |||
| 39 | 97 | for ($pos=strlen($number)-1; $pos>=0; $pos--) { |
|
| 40 | 97 | $tmp = $number[$pos] * $weight; |
|
| 41 | 97 | $sum += ($tmp > 9) ? (1 + ($tmp % 10)) : $tmp; |
|
| 42 | 97 | $weight = ($weight == 2) ? 1 : 2; |
|
| 43 | } |
||
| 44 | |||
| 45 | 97 | $ceil = $sum; |
|
| 46 | |||
| 47 | 97 | while ($ceil % 10 != 0) { |
|
| 48 | 96 | $ceil++; |
|
| 49 | } |
||
| 50 | |||
| 51 | 97 | return (string)($ceil-$sum); |
|
| 52 | } |
||
| 53 | } |
||
| 54 |