Completed
Push — master ( b09850...864f12 )
by Alexander J. Rodriguez
03:12
created

Event   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 19
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A listen() 0 3 1
A trigger() 0 13 6
1
<?php
2
3
/**
4
 * 
5
 * Events and Triggers
6
 * @author  Alexander Rodriguez <[email protected]>
7
 * 
8
 */
9
namespace App;
10
11
class Event {
12
    private static $events = [];
13
    public static function listen($name, $callback) {
14
        self::$events[$name][] = $callback;
15
    }
16
    public static function trigger($name, $argument = null) {
17
        foreach (self::$events[$name] as $event => $callback) {
18
            if($argument && is_array($argument)) {
19
                call_user_func_array($callback, $argument);
20
            }
21
            elseif ($argument && !is_array($argument)) {
22
                call_user_func($callback, $argument);
23
            }
24
            else {
25
                call_user_func($callback);
26
            }
27
        }
28
    }
29
}