DomainMessageErrorEventHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 13
ccs 11
cts 11
cp 1
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 8
nc 1
nop 2
crap 1
1
<?php
2
3
namespace MiniGameMessageApp\Error;
4
5
use Broadway\Domain\DomainEventStream;
6
use Broadway\Domain\DomainMessage;
7
use Broadway\Domain\Metadata;
8
use Broadway\EventHandling\EventBus;
9
use Broadway\Tools\Metadata\Context\ContextEnricher;
10
use League\Event\EventInterface;
11
use MessageApp\Error\ErrorEventHandler as MessageErrorEventHandler;
12
use MiniGameApp\Error\ErrorEventHandler as GameErrorEventHandler;
13
14
class DomainMessageErrorEventHandler implements GameErrorEventHandler, MessageErrorEventHandler
15
{
16
    /**
17
     * @var EventBus
18
     */
19
    private $eventBus;
20
21
    /**
22
     * Constructor
23
     *
24
     * @param EventBus $eventBus
25
     */
26 3
    public function __construct(EventBus $eventBus)
27
    {
28 3
        $this->eventBus = $eventBus;
29 3
    }
30
31
    /**
32
     * Handles an error
33
     *
34
     * @param  EventInterface $error
35
     * @param  mixed          $context
36
     *
37
     * @return void
38
     */
39 3
    public function handle(EventInterface $error, $context = null)
40
    {
41 3
        $this->eventBus->publish(
42 3
            new DomainEventStream([
43 3
                DomainMessage::recordNow(
44 3
                    null,
45 3
                    null,
46 3
                    new Metadata([ ContextEnricher::CONTEXT => $context ]),
47
                    $error
48 2
                )
49 2
            ])
50 2
        );
51 3
    }
52
}
53