EventsEmitter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 47
ccs 10
cts 10
cp 1
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A bootEvents() 0 4 1
A emit() 0 4 1
A on() 0 4 1
A off() 0 4 1
1
<?php
2
3
namespace Notimatica\Driver\Support;
4
5
use League\Event\Emitter;
6
use League\Event\EventInterface;
7
use League\Event\ListenerInterface;
8
9
trait EventsEmitter
10
{
11
    /**
12
     * @var Emitter
13
     */
14
    public static $events;
15
16
    /**
17
     * Boot events emitter.
18
     */
19 8
    public function bootEvents()
20
    {
21 8
        static::$events = new Emitter();
22 8
    }
23
24
    /**
25
     * Emit event.
26
     *
27
     * @return \League\Event\EventInterface|string
28
     */
29 4
    public static function emit()
30
    {
31 4
        return call_user_func_array([static::$events, 'emit'], func_get_args());
32
    }
33
34
    /**
35
     * Emit event.
36
     *
37
     * @param  string $event
38
     * @param  ListenerInterface|callable $listener
39
     * @return EventInterface|string
40
     */
41 1
    public static function on($event, $listener)
42
    {
43 1
        return static::$events->addListener($event, $listener);
44
    }
45
46
    /**
47
     * Remove listeners.
48
     *
49
     * @param $event
50
     */
51 1
    public static function off($event)
52
    {
53 1
        static::$events->removeAllListeners($event);
54 1
    }
55
}
56