DirectEventBus::subscribe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Domain\Eventing;
4
5
use Domain\Eventing\Exception\CorrupHandlerStack;
6
7
/**
8
 * @author Sebastiaan Hilbers <[email protected]>
9
 */
10
class DirectEventBus implements EventBus
11
{
12
    protected $listeners = [];
13
14
    public function __construct(array $handlerMap = [])
15
    {
16
        foreach ($handlerMap as $eventName => $listener) {
17
            $this->subscribe($eventName, $listener);
18
        }
19
    }
20
21
    public function publish(CommittedEvents $events)
22
    {
23
    }
24
25
    public function subscribe($eventName, Listener $listener)
0 ignored issues
show
Unused Code introduced by
The parameter $eventName is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
26
    {
27
        self::guardAgainstCorruptListener($listener);
0 ignored issues
show
Bug introduced by
The method guardAgainstCorruptListener() does not seem to exist on object<Domain\Eventing\DirectEventBus>.

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...
28
    }
29
30
    protected static function guardAgainstInvalidListener($listener)
31
    {
32
        if (!$listener instanceof Listener) {
33
            throw new CorruptHandlerStack;
34
        }
35
    }
36
}
37