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

HandAdjuster::events()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\EventHandler;
4
5
use Stratadox\CardGame\DomainEvent;
6
use Stratadox\CardGame\Match\Event\CardWasDrawn;
7
use Stratadox\CardGame\Match\Event\SpellVanishedToTheVoid;
8
use Stratadox\CardGame\Match\Event\UnitMovedIntoPlay;
9
use Stratadox\CardGame\ReadModel\Match\AllCards;
10
use Stratadox\CardGame\ReadModel\Match\CardsInHand;
11
12
final class HandAdjuster implements EventHandler
13
{
14
    private $cardsInHand;
15
    private $cards;
16
17
    public function __construct(CardsInHand $cardsInHand, AllCards $allCards)
18
    {
19
        $this->cardsInHand = $cardsInHand;
20
        $this->cards = $allCards;
21
    }
22
23
    public function events(): iterable
24
    {
25
        return [
26
            UnitMovedIntoPlay::class,
27
            SpellVanishedToTheVoid::class,
28
            CardWasDrawn::class,
29
        ];
30
    }
31
32
    public function handle(DomainEvent $event): void
33
    {
34
        if(
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after IF keyword; 0 found
Loading history...
35
            $event instanceof UnitMovedIntoPlay ||
36
            $event instanceof SpellVanishedToTheVoid
37
        ) {
38
            $this->cardsInHand->played(
39
                (string) $event->card(),
40
                $event->match(),
41
                $event->player()
42
            );
43
        } else if ($event instanceof CardWasDrawn) {
44
            $this->cardsInHand->draw(
45
                $event->match(),
46
                $event->player(),
47
                $this->cards->ofType($event->card())
48
            );
49
        }
50
    }
51
}
52