Completed
Push — master ( 438e4c...750425 )
by Jesse
02:11
created

Turn   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 26
dl 0
loc 66
rs 10
c 1
b 0
f 1
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A prohibitsPlaying() 0 5 3
A of() 0 3 1
A prohibitsStartingCombat() 0 5 3
A prohibitsDefending() 0 5 3
A prohibitsAttacking() 0 4 1
A prohibitsEndingCardPlaying() 0 4 1
A endCombatPhase() 0 6 1
A endCardPlayingPhaseFor() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Match;
4
5
use DateTimeInterface;
6
7
final class Turn
8
{
9
    private $currentPlayer;
10
    private $since;
11
    private $canPlay;
12
    private $canDefend;
13
14
    public function __construct(int $player, DateTimeInterface $since, bool $play = true)
15
    {
16
        $this->currentPlayer = $player;
17
        $this->since = $since;
18
        $this->canPlay = $play;
19
        $this->canDefend = !$play;
20
    }
21
22
    public function prohibitsPlaying(int $player, DateTimeInterface $when): bool
23
    {
24
        return $this->currentPlayer !== $player ||
25
            !$this->canPlay ||
26
            $when->getTimestamp() - $this->since->getTimestamp() >= 20;
27
    }
28
29
    public function prohibitsAttacking(int $player, DateTimeInterface $when): bool
0 ignored issues
show
Unused Code introduced by
The parameter $when is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

29
    public function prohibitsAttacking(int $player, /** @scrutinizer ignore-unused */ DateTimeInterface $when): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
30
    {
31
        // @todo check if time ran out
32
        return $this->currentPlayer !== $player;
33
    }
34
35
    public function prohibitsDefending(int $player, DateTimeInterface $when): bool
36
    {
37
        return $this->currentPlayer !== $player ||
38
            !$this->canDefend ||
39
            $when->getTimestamp() - $this->since->getTimestamp() >= 20;
40
    }
41
42
    public function prohibitsStartingCombat(int $player, DateTimeInterface $when): bool
43
    {
44
        return $this->currentPlayer !== $player ||
45
            !$this->canDefend ||
46
            $when->getTimestamp() - $this->since->getTimestamp() >= 20;
47
    }
48
49
    public function prohibitsEndingCardPlaying(int $player, DateTimeInterface $when): bool
0 ignored issues
show
Unused Code introduced by
The parameter $when is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
    public function prohibitsEndingCardPlaying(int $player, /** @scrutinizer ignore-unused */ DateTimeInterface $when): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51
        // @todo check if time ran out
52
        return $this->currentPlayer !== $player;
53
    }
54
55
    public function endCardPlayingPhaseFor(int $player): Turn
0 ignored issues
show
Unused Code introduced by
The parameter $player is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

55
    public function endCardPlayingPhaseFor(/** @scrutinizer ignore-unused */ int $player): Turn

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
    {
57
        // @todo
58
        $this->canPlay = false;
59
        return $this;
60
    }
61
62
    public function endCombatPhase(): Turn
63
    {
64
        // @todo add time
65
        $this->canDefend = false;
66
        $this->canPlay = true;
67
        return $this;
68
    }
69
70
    public function of(int $player, DateTimeInterface $since): Turn
71
    {
72
        return new Turn($player, $since, false);
73
    }
74
}
75