CardsInHand::played()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
c 0
b 0
f 0
nc 3
nop 3
dl 0
loc 9
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\ReadModel\Match;
4
5
use function array_merge;
6
use function array_values;
7
use Stratadox\CardGame\Match\MatchId;
8
9
class CardsInHand
10
{
11
    /** @var Card[][][] */
12
    private $cards = [];
13
14
    public function draw(MatchId $match, int $player, Card ...$cards): void
15
    {
16
        $this->cards[$match->id()][$player] = array_merge(
17
            $this->ofPlayer($player, $match),
18
            $cards
19
        );
20
    }
21
22
    public function played(int $offset, MatchId $match, int $player): void
23
    {
24
        foreach ($this->cards[$match->id()][$player] as $cardNumber => $cardInHand) {
25
            if ($cardInHand->offset() === $offset) {
26
                unset($this->cards[$match->id()][$player][$cardNumber]);
27
            }
28
        }
29
        $this->cards[$match->id()][$player] = array_values(
30
            $this->cards[$match->id()][$player]
31
        );
32
    }
33
34
    /** @return Card[] */
35
    public function ofPlayer(int $player, MatchId $match): array
36
    {
37
        return $this->cards[$match->id()][$player] ?? [];
38
    }
39
}
40