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

DALMediator::trigger()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 4
nc 3
nop 2
crap 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