Completed
Push — master ( 86c9ba...442812 )
by Andrew
02:54
created

Emitter::emit()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0175

Importance

Changes 6
Bugs 0 Features 1
Metric Value
c 6
b 0
f 1
dl 0
loc 12
ccs 7
cts 8
cp 0.875
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
crap 3.0175
1
<?php namespace Cairns\Radiate;
2
3
use Cairns\Radiate\Inflector\MethodInflector;
4
5
final class Emitter
6
{
7
    private $inflector;
8
9
    private $listeners = [];
10
11 3
    public function __construct(MethodInflector $inflector)
12
    {
13 3
        $this->inflector = $inflector;
14 3
    }
15
16 3
    public function addListener($listener)
17
    {
18 3
        $this->listeners[] = $listener;
19 3
    }
20
21 1
    public function getListeners()
22
    {
23 1
        return $this->listeners;
24
    }
25
26 2
    public function emit($event)
27
    {
28 2
        foreach ($this->listeners as $listener) {
29 2
            $method = $this->inflector->inflect($event, $listener);
30
31 2
            if (! method_exists($listener, $method)) {
32
                continue;
33
            }
34
35 2
            call_user_func_array([$listener, $method], func_get_args());
36 2
        }
37 2
    }
38
}
39