Completed
Push — Bowlingkata/xavi ( 102cc8...ba9024 )
by
unknown
01:55
created

Bowling::__invoke()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 26
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.4661

Importance

Changes 0
Metric Value
dl 0
loc 26
ccs 9
cts 13
cp 0.6923
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 13
nc 4
nop 1
crap 4.4661
1
<?php
2
3
namespace Kata\BowlingKata;
4
5
final class Bowling
6
{
7 7
    public function __invoke(array $tries) : int
8
    {
9 7
        $punctuation = 0;
10
11 7
        foreach ($tries as $num_try => $try)
12
        {
13 7
            if ($this->isATryWithStrike($try))
14
            {
15
                $current_punctuation = 10 + $tries[$num_try+1] + $tries[$num_try+2];
16
                $punctuation+= $current_punctuation;
17
                continue;
18
            }
19
20 7
            if ($this->isAFrameWithSpare($tries, $num_try))
21
            {
22 2
                $current_punctuation = 10 + $tries[$num_try+2];
23
24 2
                $punctuation+=$current_punctuation;
25 2
                continue;
26
            }
27
28 7
            $punctuation+= $try;
29
        }
30
31
        return $punctuation;
32
    }
33
34 7
    private function isAFrameWithSpare($tries, $num_try)
35
    {
36 7
        return isset($tries[$num_try+1]) && $tries[$num_try+1]  === '/';
37
    }
38
39 7
    private function isATryWithStrike($try)
40
    {
41 7
        return $try === 'X';
42
    }
43
}
44