DomainMessageErrorEventHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 39
ccs 14
cts 14
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 13 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