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