Passed
Push — master ( 30d3d2...4e3abd )
by Jesse
01:56
created

Turn::isInTime()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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
        return $this->currentPlayer !== $player;
32
    }
33
34
    public function prohibitsDefending(int $player, DateTimeInterface $when): bool
35
    {
36
        return $this->currentPlayer !== $player ||
37
            !$this->canDefend ||
38
            $when->getTimestamp() - $this->since->getTimestamp() >= 20;
39
    }
40
41
    public function endCardPlayingPhaseFor(int $thePlayer): Turn
0 ignored issues
show
Unused Code introduced by
The parameter $thePlayer 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

41
    public function endCardPlayingPhaseFor(/** @scrutinizer ignore-unused */ int $thePlayer): 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...
42
    {
43
        // @todo
44
        $this->canPlay = false;
45
        return $this;
46
    }
47
48
    public function endCombatPhase(): Turn
49
    {
50
        // @todo add time
51
        $this->canDefend = false;
52
        $this->canPlay = true;
53
        return $this;
54
    }
55
56
    public function of(int $thePlayer, DateTimeInterface $since): Turn
57
    {
58
        return new Turn($thePlayer, $since, false);
59
    }
60
}
61