DirectEventBus   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 27
wmc 6
lcom 0
cbo 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A publish() 0 3 1
A subscribe() 0 4 1
A guardAgainstInvalidListener() 0 6 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