Event   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

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