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

AbstractThreadPoolMediator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Wonderland\Thread;
4
5
use Wonderland\Thread\Mediator\Listener\ListenerInterface;
6
use Wonderland\Thread\Mediator\Mediator;
7
use Wonderland\Thread\Factory\EventPoolFactory;
8
9
abstract class AbstractThreadPoolMediator
10
{
11
	/** @var Mediator */
12
	private $mediator;
13
14
	/**
15
	 * @return Mediator
16
	 */
17
	protected function getMediator()
18
	{
19
		return $this->mediator;
20
	}
21
22
	/**
23
	 * ThreadPoolMediator constructor.
24
	 */
25 6
	public function __construct()
26
	{
27 6
		$this->mediator = new Mediator();
28 6
	}
29
30
	/**
31
	 * @param ListenerInterface $listener
32
	 * @return AbstractThreadPoolMediator
33
	 */
34
	public function addListener(ListenerInterface $listener): self
35
	{
36
		$this->mediator->addListener($listener);
37
38
		return $this;
39
	}
40
41
	/**
42
	 * @param ListenerInterface $listener
43
	 * @return AbstractThreadPoolMediator
44
	 */
45
	public function removeListener(ListenerInterface $listener): self
46
	{
47
		$this->mediator->removeListener($listener);
48
49
		return $this;
50
	}
51
52
	/**
53
	 * @param string              $eventName
54
	 * @param AbstractThread|null $thread
55
	 */
56
	protected function notify(string $eventName, ?AbstractThread $thread = null)
57
	{
58
		$this->getMediator()->notify(EventPoolFactory::create($eventName, $this, $thread));
59
	}
60
61
}
62