MessageDispatchingEventDispatcher   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 3 1
A __construct() 0 4 2
A dispatchWithHeaders() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing;
6
7
class MessageDispatchingEventDispatcher implements EventDispatcher
8
{
9
    private MessageDispatcher $dispatcher;
10
    private MessageDecorator $decorator;
11
12
    public function __construct(MessageDispatcher $dispatcher, ?MessageDecorator $decorator = null)
13
    {
14
        $this->dispatcher = $dispatcher;
15
        $this->decorator = $decorator ?: new DefaultHeadersDecorator();
16
    }
17
18
    public function dispatch(object ...$events): void
19 2
    {
20
        $this->dispatchWithHeaders([], ...$events);
21 2
    }
22 2
23 2
    public function dispatchWithHeaders(array $headers, object ...$events): void
24
    {
25 1
        $messages = [];
26
27 1
        foreach ($events as $event) {
28 1
            $messages[] = $this->decorator->decorate(new Message($event, $headers));
29
        }
30 2
31
        $this->dispatcher->dispatch(...$messages);
32 2
    }
33
}
34