Location::inDeck()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
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 function assert;
6
7
final class Location
8
{
9
    private const IN_DECK = 0;
10
    private const IN_HAND = 1;
11
    private const IN_PLAY = 2;
12
    private const IN_ATTACK = 3;
13
    private const IN_DEFENCE = 3;
14
    private const IN_VOID = 4;
15
16
    private $realm;
17
    private $position;
18
19
    private function __construct(int $realm, ?int $position)
20
    {
21
        $this->realm = $realm;
22
        $this->position = $position;
23
    }
24
25
    public static function inDeck(int $position): Location
26
    {
27
        return new self(Location::IN_DECK, $position);
28
    }
29
30
    private static function inHand(int $position): Location
31
    {
32
        return new self(Location::IN_HAND, $position);
33
    }
34
35
    public static function inPlay(int $position): Location
36
    {
37
        return new self(Location::IN_PLAY, $position);
38
    }
39
40
    public static function attackingAt(int $position): Location
41
    {
42
        return new self(Location::IN_ATTACK, $position);
43
    }
44
45
    public static function defendingAgainst(int $position): Location
46
    {
47
        return new self(Location::IN_DEFENCE, $position);
48
    }
49
50
    public static function inVoid(): Location
51
    {
52
        return new self(Location::IN_VOID, null);
53
    }
54
55
    public function isInHand(): bool
56
    {
57
        return $this->realm === Location::IN_HAND;
58
    }
59
60
    public function isInPlay(): bool
61
    {
62
        return $this->realm === Location::IN_PLAY
63
            || $this->realm === Location::IN_ATTACK;
64
//            || $this->realm === Location::IN_DEFENCE;
65
    }
66
67
    public function isAttacking(): bool
68
    {
69
        return $this->realm === Location::IN_ATTACK;
70
    }
71
72
    public function isDefending(): bool
73
    {
74
        return $this->realm === Location::IN_DEFENCE;
75
    }
76
77
    public function isAttackingThe(Location $defenderLocation): bool
78
    {
79
        return $defenderLocation->isDefending();
80
        // @todo && $this->isAttacking()
81
        // @todo && $this->position === $defenderLocation->position;
82
    }
83
84
    public function isInDeck(): bool
85
    {
86
        return $this->realm === Location::IN_DECK;
87
    }
88
89
    public function hasHigherPositionThan(Location $other): bool
90
    {
91
        assert($this->realm === $other->realm);
92
        return $this->position > $other->position;
93
    }
94
95
    public function toHand(int $position): Location
96
    {
97
        return Location::inHand($position);
98
    }
99
}
100