Test Setup Failed
Push — master ( a63fa0...36623d )
by Jesse
04:59
created

OngoingMatch::startTurnOf()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\ReadModel\Match;
4
5
use Stratadox\CardGame\Match\MatchId;
6
7
final class OngoingMatch
8
{
9
    public const PHASE_DEFEND = 'defend';
10
    public const PHASE_PLAY = 'play';
11
    public const PHASE_ATTACK = 'attack';
12
13
    private $id;
14
    private $turn;
15
    private $phase = self::PHASE_PLAY;
16
17
    public function __construct(MatchId $match, int $whoStarts)
18
    {
19
        $this->id = $match;
20
        $this->turn = $whoStarts;
21
    }
22
23
    public function id(): MatchId
24
    {
25
        return $this->id;
26
    }
27
28
    /** @return int[] */
29
    public function players(): array
30
    {
31
        return [0, 1];
32
    }
33
34
    public function startTurnOf(int $player): void
35
    {
36
        $this->turn = $player;
37
        $this->phase = self::PHASE_DEFEND;
38
    }
39
40
    public function itIsTheTurnOf(int $player): bool
41
    {
42
        return $this->turn === $player;
43
    }
44
45
    public function startDefendPhase(): void
46
    {
47
        $this->phase = self::PHASE_DEFEND;
48
    }
49
50
    public function startPlayPhase(): void
51
    {
52
        $this->phase = self::PHASE_PLAY;
53
    }
54
55
    public function startAttackPhase(): void
56
    {
57
        $this->phase = self::PHASE_ATTACK;
58
    }
59
60
    public function phase(): string
61
    {
62
        return $this->phase;
63
    }
64
}
65