Completed
Push — master ( 83d287...68abc7 )
by Andrew
02:20
created

Emitter::getListeners()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 2
    public function __construct(MethodInflector $inflector)
12
    {
13 2
        $this->inflector = $inflector;
14 2
    }
15
16 2
    public function addListener($listener)
17
    {
18 2
        $this->listeners[] = $listener;
19 2
    }
20
21 1
    public function getListeners()
22
    {
23 1
        return $this->listeners;
24
    }
25
26 1
    public function emit($event)
27
    {
28 1
        foreach ($this->listeners as $listener) {
29 1
            $method = $this->inflector->inflect($event, $listener);
30
31 1
            if (! method_exists($listener, $method)) {
32
                continue;
33
            }
34
35 1
            $listener->{$method}($event);
36 1
        }
37 1
    }
38
}
39