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

DecoratingMessageDispatcher::__construct()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

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