Completed
Push — master ( 0287cb...35c8bf )
by Dmitry
04:37
created

Event   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 7
c 5
b 1
f 1
lcom 1
cbo 3
dl 0
loc 39
ccs 0
cts 27
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B fireChanges() 0 25 6
1
<?php
2
3
namespace Basis;
4
5
use Tarantool\Mapper\Plugins\Spy;
6
7
class Event
8
{
9
    private $dispatcher;
10
    private $service;
11
    private $spy;
12
13
    public function __construct(Dispatcher $dispatcher, Service $service, Spy $spy)
14
    {
15
        $this->dispatcher = $dispatcher;
16
        $this->service = $service;
17
        $this->spy = $spy;
18
    }
19
20
    public function fireChanges()
21
    {
22
        if($this->spy->hasChanges()) {
23
            // reduce changes list
24
            $changes = $this->spy->getChanges();
25
            foreach($changes as $action => $collection) {
26
                foreach($collection as $space => $entities) {
27
28
                    $event = $this->service->getName().'.'.$space.'.'.$action;
29
30
                    if(!$this->service->eventExists($event)) {
31
                        unset($collection[$space]);
32
                    }
33
                }
34
                if(!count($collection)) {
35
                    unset($changes[$action]);
36
                }
37
            }
38
39
            $this->dispatcher->dispatch('event.changes', [
40
                'changes' => $spy->getChanges(),
0 ignored issues
show
Bug introduced by
The variable $spy does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
41
                'service' => $this->service,
42
            ]);
43
        }
44
    }
45
}
46