InvokeListenerMiddleware   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 54
ccs 14
cts 16
cp 0.875
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
B execute() 0 22 4
1
<?php namespace Cairns\Radiate\Middleware;
2
3
use Cairns\Radiate\Inflector\MethodInflector;
4
use Cairns\Radiate\Registry\Registry;
5
use Cairns\Radiate\Locator\ListenerLocator;
6
7
class InvokeListenerMiddleware implements Middleware
8
{
9
    /**
10
     * @var Registry
11
     */
12
    private $listeners;
13
14
    /**
15
     * @var ListenerLocator
16
     */
17
    private $locator;
18
19
    /**
20
     * @var MethodInflector
21
     */
22
    private $inflector;
23
24
    /**
25
     * @param Registry $listeners
26
     * @param ListenerLocator $locator
27
     * @param MethodInflector $inflector
28
     */
29 1
    public function __construct(Registry $listeners, ListenerLocator $locator, MethodInflector $inflector)
30
    {
31 1
        $this->listeners = $listeners;
32
33 1
        $this->locator = $locator;
34
35 1
        $this->inflector = $inflector;
36 1
    }
37
38 1
    public function execute($event, callable $next)
39
    {
40 1
        $listeners = $this->listeners->find($event);
41
42 1
        if (! $listeners) {
43
            return $next($event);
44
        }
45
46 1
        foreach ($listeners as $listener) {
47 1
            $method = $this->inflector->inflect($event, $listener);
48
49 1
            if (! $method) {
50
                continue;
51
            }
52
53 1
            $listener = $this->locator->locate($listener);
54
55 1
            call_user_func([$listener, $method], $event);
56
        }
57
58 1
        return $next($event);
59
    }
60
}
61