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

OngoingMatch   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 56
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A startAttackPhase() 0 3 1
A itIsTheTurnOf() 0 3 1
A id() 0 3 1
A phase() 0 3 1
A startDefendPhase() 0 3 1
A startTurnOf() 0 4 1
A __construct() 0 4 1
A players() 0 3 1
A startPlayPhase() 0 3 1
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