Passed
Pull Request — master (#84)
by Frank
07:08
created

DecoratingMessageDispatcher::dispatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
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
    public function __construct(MessageDispatcher $dispatcher, MessageDecorator $decorator = null)
20
    {
21
        $this->dispatcher = $dispatcher;
22
        $this->decorator = $decorator ?: new DefaultHeadersDecorator();
23
    }
24
25
    public function dispatch(Message ...$messages): void
26
    {
27
        $messages = array_map(fn (Message $message) => $this->decorator->decorate($message), $messages);
28
        $this->dispatcher->dispatch(...$messages);
29
    }
30
}
31