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

Roll   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 52
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fromMark() 0 18 4
A increaseScore() 0 4 1
A type() 0 4 1
A score() 0 4 1
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