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

Roll::fromMark()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
crap 4
1
<?php
2
3
namespace Kata\BowlingKata\Domain;
4
5
final class Roll
6
{
7
    /** @var string */
8
    private $mark;
9
10
    /** @var int|null */
11
    private $score;
12
13
    /** @var RollType */
14
    private $type;
15
16 34
    public function __construct(string $a_mark, int $a_score = null)
17
    {
18 34
        $this->mark  = $a_mark;
19 34
        $this->score = $a_score;
20 34
        $this->type  = RollType::fromMark($a_mark);
1 ignored issue
show
Documentation Bug introduced by
It seems like \Kata\BowlingKata\Domain...Type::fromMark($a_mark) of type object<self> is incompatible with the declared type object<Kata\BowlingKata\Domain\RollType> of property $type.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
21 34
    }
22
23 34
    public static function fromMark($a_mark)
24
    {
25 34
        $roll_type = RollType::fromMark($a_mark);
26
27 34
        if ($roll_type->isSpare()) {
28 12
            return new self($a_mark);
29
        }
30
31 34
        if ($roll_type->isStrike()) {
32 14
            return new self($a_mark, 10);
33
        }
34
35 32
        if ($roll_type->isEmpty()) {
36 30
            return new self($a_mark, 0);
37
        }
38
39 28
        return new self($a_mark, (int)$a_mark);
40
    }
41
42 22
    public function increaseScore($a_score)
43
    {
44 22
        $this->score += $a_score;
45 22
    }
46
47 34
    public function type() : RollType
48
    {
49 34
        return $this->type;
50
    }
51
52 34
    public function score() : int
53
    {
54 34
        return $this->score;
55
    }
56
}
57