Completed
Push — master ( 1c2448...72431b )
by Andrew
03:14 queued 01:00
created

Emitter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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