HasEvents::setEventEmitter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Personnage\Tinkoff\SDK;
4
5
use League\Event\EmitterInterface;
6
7
trait HasEvents
8
{
9
    /**
10
     * @var EmitterInterface
11
     */
12
    private $emitter;
13
14
    /**
15
     * Get the event emitter instance.
16
     *
17
     * @return EmitterInterface|null
18
     */
19
    public function getEventEmitter()
20
    {
21
        return $this->emitter;
22
    }
23
24
    /**
25
     * Set the event emitter instance.
26
     *
27
     * @param EmitterInterface $emitter
28
     */
29
    public function setEventEmitter(EmitterInterface $emitter)
30
    {
31
        $this->emitter = $emitter;
32
    }
33
34
    /**
35
     * Unset the event emitter.
36
     */
37
    public function unsetEventEmitter()
38
    {
39
        $this->emitter = null;
40
    }
41
42
    /**
43
     * Emit an event.
44
     *
45
     * @param  string  $eventClassName
46
     * @param  array   $payload
47
     */
48 3
    protected function fire(string $eventClassName, array $payload)
49
    {
50 3
        if ($this->emitter) {
51
            $this->emitter->emit(new $eventClassName(...$payload));
52
        }
53 3
    }
54
}
55