| Conditions | 4 |
| Paths | 5 |
| Total Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | 4 | protected function calculateSum(string $number): int |
|
| 43 | { |
||
| 44 | 4 | $weight = 2; |
|
| 45 | 4 | $sum = 0; |
|
| 46 | |||
| 47 | 4 | for ($pos=strlen($number)-1; $pos>=0; $pos--) { |
|
| 48 | 4 | $tmp = $number[$pos] * $weight; |
|
| 49 | 4 | $sum += ($tmp > 9) ? (1 + ($tmp % 10)) : $tmp; |
|
| 50 | 4 | $weight = ($weight == 2) ? 1 : 2; |
|
| 51 | } |
||
| 52 | |||
| 53 | 4 | return $sum; |
|
| 54 | } |
||
| 55 | } |
||
| 56 |