Completed
Push — Bowlingkata/Albert ( a8d0e2...ff2053 )
by Albert
02:01
created

RollCollection::offsetUnset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Kata\BowlingKata\Domain;
4
5
final class RollCollection implements \Iterator, \ArrayAccess
6
{
7
    private $roll_array;
8
9 34
    public function __construct(array $a_roll_content_array)
10
    {
11 34
        $roll_array = [];
12 34
        foreach ($a_roll_content_array as $key => $roll_content) {
13 34
            $roll = Roll::fromMark($roll_content);
14
15 34
            if ($roll->type()->isSpare()) {
16 12
                $roll->increaseScore(Frame::MAX_FRAME_SCORE - Roll::fromMark($a_roll_content_array[$key - 1])->score());
17
            }
18
19 34
            $roll_array[] = $roll;
20
        }
21
22 34
        $this->roll_array = $roll_array;
23 34
    }
24
25 34
    public function current()
26
    {
27 34
        return current($this->roll_array);
28
    }
29
30 34
    public function next()
31
    {
32 34
        return next($this->roll_array);
33
    }
34
35
    public function key()
36
    {
37
        return key($this->roll_array);
38
    }
39
40 34
    public function valid()
41
    {
42 34
        return current($this->roll_array);
43
    }
44
45 34
    public function rewind()
46
    {
47 34
        return reset($this->roll_array);
48
    }
49
50 22
    public function offsetExists($offset)
51
    {
52 22
        return isset($this->roll_array[$offset]);
53
    }
54
55 22
    public function offsetGet($offset)
56
    {
57 22
        return $this->roll_array[$offset];
58
    }
59
60
    public function offsetSet($offset, $value)
61
    {
62
        return $this->roll_array[$offset] = $value;
63
    }
64
65
    public function offsetUnset($offset)
66
    {
67
        unset($this->roll_array[$offset]);
68
    }
69
}
70