Passed
Push — master ( 30d3d2...4e3abd )
by Jesse
01:56
created

TurnSwitcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 7 1
A becameTheTurnOf() 0 5 1
A events() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\EventHandler;
4
5
use function assert;
6
use Stratadox\CardGame\DomainEvent;
7
use Stratadox\CardGame\Match\Event\NextTurnBegan;
8
use Stratadox\CardGame\ReadModel\Match\OngoingMatch;
9
use Stratadox\CardGame\ReadModel\Match\OngoingMatches;
10
11
final class TurnSwitcher implements EventHandler
12
{
13
    /** @var OngoingMatches */
14
    private $ongoingMatches;
15
16
    public function __construct(OngoingMatches $ongoingMatches)
17
    {
18
        $this->ongoingMatches = $ongoingMatches;
19
    }
20
21
    public function events(): iterable
22
    {
23
        return [NextTurnBegan::class];
24
    }
25
26
    public function handle(DomainEvent $nextTurn): void
27
    {
28
        assert($nextTurn instanceof NextTurnBegan);
29
30
        $this->becameTheTurnOf(
31
            $nextTurn->player(),
32
            $this->ongoingMatches->withId($nextTurn->match())
33
        );
34
    }
35
36
    private function becameTheTurnOf(
37
        int $theNextPlayer,
38
        OngoingMatch $inTheMatch
39
    ): void {
40
        $inTheMatch->beganTheTurnOf($theNextPlayer);
41
    }
42
}
43