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

DecoratingMessageDispatcher::dispatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 1
rs 10
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