Completed
Push — master ( ab4a72...99f0f9 )
by Sergey
05:20
created

DALMediator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 24
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A attach() 0 7 2
A trigger() 0 8 3
1
<?php
2
3
namespace Isswp101\Persimmon\DAL;
4
5
class DALMediator
6
{
7
    const EVENT_BEFORE_SEARCH = 'EVENT_BEFORE_SEARCH';
8
    const EVENT_AFTER_SEARCH = 'EVENT_AFTER_SEARCH';
9
10
    protected $events = [];
11
12 54
    public function attach($event, callable $callback)
13
    {
14 54
        if (!isset($this->events[$event])) {
15 54
            $this->events[$event] = [];
16 54
        }
17 54
        $this->events[$event][] = $callback;
18 54
    }
19
20 22
    public function trigger($event, $data = null)
21
    {
22 22
        if (isset($this->events[$event])) {
23 22
            foreach ($this->events[$event] as $callback) {
24 22
                $callback($data);
25 22
            }
26 22
        }
27 22
    }
28
}
29