Completed
Push — master ( 4817b6...ad4d8c )
by Frank
02:04
created

dispatchWithHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EventSauce\EventSourcing;
6
7
class MessageDispatchingEventDispatcher implements EventDispatcher
8
{
9
    /**
10
     * @var MessageDispatcher
11
     */
12
    private $dispatcher;
13
14
    /**
15
     * @var MessageDecorator|null
16
     */
17
    private $decorator;
18
19 2
    public function __construct(MessageDispatcher $dispatcher, ?MessageDecorator $decorator = null)
20
    {
21 2
        $this->dispatcher = $dispatcher;
22 2
        $this->decorator = $decorator ?: new DefaultHeadersDecorator();
23 2
    }
24
25 1
    public function dispatch(object ...$events): void
26
    {
27 1
        $this->dispatchWithHeaders([], ...$events);
28 1
    }
29
30 2
    public function dispatchWithHeaders(array $headers, object ...$events): void
31
    {
32 2
        $messages = [];
33
34 2
        foreach ($events as $event) {
35 2
            $messages[] = $this->decorator->decorate(new Message($event, $headers));
0 ignored issues
show
Bug introduced by Frank de Jonge
The method decorate() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
            /** @scrutinizer ignore-call */ 
36
            $messages[] = $this->decorator->decorate(new Message($event, $headers));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
36
        }
37
38 2
        $this->dispatcher->dispatch(...$messages);
39 2
    }
40
}
41