Completed
Push — master ( 756481...5cbf4f )
by Andrew
02:54
created

InvokeListenerMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 92.86%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 46
ccs 13
cts 14
cp 0.9286
rs 10

2 Methods

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