Completed
Push — master ( 2ef5a2...0a610c )
by Dmitry
04:17
created

Event::fireChanges()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Basis;
4
5
use Tarantool\Mapper\Plugins\Spy;
6
7
class Event
8
{
9
    private $dispatcher;
10
11
    public function __construct(Dispatcher $dispatcher)
12
    {
13
        $this->dispatcher = $dispatcher;
14
    }
15
16
    public function fire($event, $context)
17
    {
18
        $this->dispatcher->dispatch('event.fire', [
19
            'event' => $event,
20
            'context' => $context
21
        ]);
22
    }
23
24
    public function fireChanges(Spy $spy)
25
    {
26
        if($spy->hasChanges()) {
27
            $this->dispatcher->dispatch('event.changes', $spy->getChanges());
28
        }
29
    }
30
31
    public function subscribe($event, $listener)
32
    {
33
        $this->dispatcher->dispatch('event.subscribe', [
34
            'event' => $event,
35
            'listener' => $listener,
36
        ]);
37
    }
38
39
    public function unsubscribe($event, $listener)
40
    {
41
        $this->dispatcher->dispatch('event.unsubscribe', [
42
            'event' => $event,
43
            'listener' => $listener,
44
        ]);
45
    }
46
}
47