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

Event   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 40
ccs 0
cts 31
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fire() 0 7 1
A fireChanges() 0 6 2
A subscribe() 0 7 1
A unsubscribe() 0 7 1
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