CardsInHand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A draw() 0 5 1
A ofPlayer() 0 3 1
A played() 0 9 3
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