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

CombatProcess   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A handle() 0 7 1
A timeForCombat() 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\EndBlocking;
8
use Stratadox\CardGame\Match\Match;
9
use Stratadox\CardGame\Match\Matches;
10
use Stratadox\Clock\Clock;
11
use Stratadox\CommandHandling\Handler;
12
13
final class CombatProcess implements Handler
14
{
15
    /** @var Matches */
16
    private $matches;
17
    /** @var Clock */
18
    private $clock;
19
    /** @var EventBag */
20
    private $eventBag;
21
22
    public function __construct(
23
        Matches $matches,
24
        Clock $clock,
25
        EventBag $eventBag
26
    ) {
27
        $this->matches = $matches;
28
        $this->clock = $clock;
29
        $this->eventBag = $eventBag;
30
    }
31
32
    public function handle(object $command): void
33
    {
34
        assert($command instanceof EndBlocking);
35
36
        $this->timeForCombat(
37
            $command->player(),
38
            $this->matches->withId($command->match())
39
        );
40
    }
41
42
    private function timeForCombat(int $thePlayer, Match $theMatch): void
43
    {
44
        $theMatch->letTheCombatBegin($thePlayer, $this->clock->now());
45
46
        $this->eventBag->takeFrom($theMatch);
47
    }
48
}
49