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

Bowling::isAFrameWithSpare()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
crap 2
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