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

BringerOfBadNews::handle()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 20
nc 64
nop 1
dl 0
loc 31
rs 8.6666
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\EventHandler;
4
5
use Stratadox\CardGame\Account\TriedOpeningAccountForUnknownEntity;
6
use Stratadox\CardGame\DomainEvent;
7
use Stratadox\CardGame\Match\Event\PlayerDidNotHaveTheMana;
8
use Stratadox\CardGame\Match\Event\TriedPlayingCardOutOfTurn;
9
use Stratadox\CardGame\Match\Event\TriedStartingMatchForPendingProposal;
10
use Stratadox\CardGame\Proposal\TriedAcceptingExpiredProposal;
11
use Stratadox\CardGame\Proposal\TriedAcceptingUnknownProposal;
12
use Stratadox\CardGame\ReadModel\Refusals;
13
14
final class BringerOfBadNews implements EventHandler
15
{
16
    private $refusals;
17
18
    public function __construct(Refusals $refusals)
19
    {
20
        $this->refusals = $refusals;
21
    }
22
23
    public function handle(DomainEvent $event): void
24
    {
25
        if ($event instanceof TriedOpeningAccountForUnknownEntity) {
26
            $this->refusals->addFor(
27
                $event->aggregateId(),
28
                'Cannot open account for unknown entity'
29
            );
30
        }
31
        if ($event instanceof TriedStartingMatchForPendingProposal) {
32
            $this->refusals->addFor(
33
                $event->aggregateId(),
34
                'The proposal is still pending!'
35
            );
36
        }
37
        if ($event instanceof TriedAcceptingExpiredProposal) {
38
            $this->refusals->addFor(
39
                $event->aggregateId(),
40
                'The proposal has already expired!'
41
            );
42
        }
43
        if ($event instanceof TriedAcceptingUnknownProposal) {
44
            $this->refusals->addFor(
45
                $event->aggregateId(),
46
                'Proposal not found'
47
            );
48
        }
49
        if ($event instanceof PlayerDidNotHaveTheMana) {
50
            $this->refusals->addFor($event->aggregateId(), 'Not enough mana!');
51
        }
52
        if ($event instanceof TriedPlayingCardOutOfTurn) {
53
            $this->refusals->addFor($event->aggregateId(), 'Cannot play cards right now');
54
        }
55
    }
56
}
57