Completed
Push — master ( 4b1e3c...30d3d2 )
by Jesse
02:57
created

EndPlayPhaseProcess   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 1
A __construct() 0 4 1
A endPlayPhase() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Match\Handler;
4
5
use function assert;
6
use Stratadox\CardGame\EventBag;
7
use Stratadox\CardGame\Match\Command\EndCardPlaying;
8
use Stratadox\CardGame\Match\Match;
9
use Stratadox\CardGame\Match\Matches;
10
use Stratadox\CommandHandling\Handler;
11
12
final class EndPlayPhaseProcess implements Handler
13
{
14
    private $matches;
15
    private $eventBag;
16
17
    public function __construct(Matches $matches, EventBag $eventBag)
18
    {
19
        $this->matches = $matches;
20
        $this->eventBag = $eventBag;
21
    }
22
23
    public function handle(object $command): void
24
    {
25
        assert($command instanceof EndCardPlaying);
26
27
        $this->endPlayPhase(
28
            $command->player(),
29
            $this->matches->withId($command->match())
30
        );
31
    }
32
33
    private function endPlayPhase(int $thePlayer, Match $theMatch): void
34
    {
35
        $theMatch->endCardPlayingPhaseFor($thePlayer);
36
37
        $this->eventBag->takeFrom($theMatch);
38
    }
39
}
40