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

AbstractThreadPoolMediator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 23.08%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 50
ccs 3
cts 13
cp 0.2308
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addListener() 0 5 1
A getMediator() 0 3 1
A removeListener() 0 5 1
A notify() 0 3 1
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