Test Setup Failed
Push — master ( 647a95...23a558 )
by Jesse
02:13
created

TurnPhase   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 57
rs 10
c 1
b 0
f 0
wmc 11

10 Methods

Rating   Name   Duplication   Size   Complexity  
A endCardPlaying() 0 3 1
A prohibitsAttacking() 0 3 1
A prohibitsPlaying() 0 3 1
A endCombat() 0 3 1
A __construct() 0 3 1
A defend() 0 3 1
A isAfterCombat() 0 4 2
A play() 0 3 1
A prohibitsDefending() 0 3 1
A attack() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Match;
4
5
final class TurnPhase
6
{
7
    private const DEFEND = 0;
8
    private const PLAY = 1;
9
    private const ATTACK = 2;
10
11
    private $phase;
12
13
    private function __construct(int $phase)
14
    {
15
        $this->phase = $phase;
16
    }
17
18
    public static function defend(): self
19
    {
20
        return new self(TurnPhase::DEFEND);
21
    }
22
23
    public static function play(): self
24
    {
25
        return new self(TurnPhase::PLAY);
26
    }
27
28
    public static function attack(): self
29
    {
30
        return new self(TurnPhase::ATTACK);
31
    }
32
33
    public function prohibitsDefending(): bool
34
    {
35
        return $this->phase !== TurnPhase::DEFEND;
36
    }
37
38
    public function prohibitsPlaying(): bool
39
    {
40
        return $this->phase !== TurnPhase::PLAY;
41
    }
42
43
    public function prohibitsAttacking(): bool
44
    {
45
        return $this->phase !== TurnPhase::ATTACK;
46
    }
47
48
    public function isAfterCombat(): bool
49
    {
50
        return $this->phase === TurnPhase::PLAY
51
            || $this->phase === TurnPhase::ATTACK;
52
    }
53
54
    public function endCombat(): TurnPhase
55
    {
56
        return TurnPhase::play();
57
    }
58
59
    public function endCardPlaying(): TurnPhase
60
    {
61
        return TurnPhase::attack();
62
    }
63
}
64