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