Completed
Push — master ( 1155e5...128653 )
by Sergey
05:42
created

EventEmitter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

2 Methods

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