Listener::setEventName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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