Passed
Pull Request — master (#84)
by Frank
10:15 queued 08:09
created

DecoratingMessageDispatcher   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A dispatch() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing;
6
7
class DecoratingMessageDispatcher implements MessageDispatcher
8
{
9
    /**
10
     * @var MessageDispatcher
11
     */
12
    private $dispatcher;
13
14
    /**
15
     * @var MessageDecorator
16
     */
17
    private $decorator;
18
19 1
    public function __construct(MessageDispatcher $dispatcher, MessageDecorator $decorator = null)
20
    {
21 1
        $this->dispatcher = $dispatcher;
22 1
        $this->decorator = $decorator ?: new DefaultHeadersDecorator();
23 1
    }
24
25 1
    public function dispatch(Message ...$messages): void
26
    {
27 1
        $messages = array_map(
28 1
            function ($message) {
29 1
                return $this->decorator->decorate($message);
30 1
            },
31
            $messages
32
        );
33
34 1
        $this->dispatcher->dispatch(...$messages);
35 1
    }
36
}
37