Event   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
dl 0
loc 30
ccs 0
cts 9
cp 0
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A subscribe() 0 7 2
A trigger() 0 10 3
1
<?php
2
3
namespace LE_ACME2\Utilities;
4
5
use LE_ACME2\SingletonTrait;
6
7
class Event {
8
9
    const EVENT_CONNECTOR_WILL_REQUEST = 'EVENT_CONNECTOR_WILL_REQUEST';
10
11
    use SingletonTrait;
12
13
    private $_subscriber = [];
14
15
    /**
16
     * @param callable $callable function(string $event, array $payload = null)
17
     */
18
    public function subscribe(string $event, callable $callable) : void {
19
20
        if(!isset($this->_subscriber[$event])) {
21
            $this->_subscriber[$event] = [];
22
        }
23
24
        $this->_subscriber[$event][] = $callable;
25
    }
26
    
27
    public function trigger(string $event, array $payload = null) : void {
28
29
        Logger::getInstance()->add(Logger::LEVEL_DEBUG, 'Event triggered: ' . $event);
0 ignored issues
show
Bug introduced by
It seems like add() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        Logger::getInstance()->/** @scrutinizer ignore-call */ add(Logger::LEVEL_DEBUG, 'Event triggered: ' . $event);
Loading history...
30
31
        if(!isset($this->_subscriber[$event])) {
32
            return;
33
        }
34
35
        foreach($this->_subscriber[$event] as $callable) {
36
            $callable($event, $payload);
37
        }
38
    }
39
}