HasEvents   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 25%

Importance

Changes 0
Metric Value
dl 0
loc 48
ccs 3
cts 12
cp 0.25
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventEmitter() 0 4 1
A setEventEmitter() 0 4 1
A unsetEventEmitter() 0 4 1
A fire() 0 6 2
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