Test Failed
Pull Request — master (#10)
by Alice
04:15
created

Mediator::notify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wonderland\Thread\Mediator;
4
5
use Wonderland\Thread\Mediator\Event\EventInterface;
6
use Wonderland\Thread\Mediator\Listener\ListenerInterface;
7
8
class Mediator
9
{
10
	/** @var ListenerInterface[] */
11
	private $listeners = [];
12
13
	/**
14
	 * @return ListenerInterface[]
15
	 */
16
	public function getListeners(): array
17
	{
18
		return $this->listeners;
19
	}
20
21
	/**
22
	 * @param ListenerInterface $listener
23
	 * @return Mediator
24
	 */
25
	public function addListener(ListenerInterface $listener): self
26
	{
27
		$this->listeners[] = $listener;
28
29
		return $this;
30
	}
31
32
	/**
33
	 * @param ListenerInterface $listener
34
	 * @return Mediator
35
	 */
36
	public function removeListener(ListenerInterface $listener): self
37
	{
38
        if (false !== ($key = array_search($listener, $this->listeners, true))) {
39
            unset($this->listeners[$key]);
40
        }
41
42
		return $this;
43
	}
44
45
	/**
46
	 * @param EventInterface $event
47
	 */
48
	public function notify(EventInterface $event)
49
	{
50
		foreach ($this->listeners as $listener) {
51
			$listener->notify($event);
52
		}
53
	}
54
55
}
56