Completed
Push — master ( 21f279...d6aafa )
by Maxim
02:34
created

EventsEmitter::makeStatisticsStorage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 4
cts 6
cp 0.6667
rs 9.4285
cc 3
eloc 5
nc 3
nop 0
crap 3.3332
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 9
    public function bootEvents()
20
    {
21 9
        static::$events = new Emitter();
22
23 9
        $this->bootListeners();
0 ignored issues
show
Bug introduced by
It seems like bootListeners() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
24 9
    }
25
26
    /**
27
     * Emit event.
28
     *
29
     * @return \League\Event\EventInterface|string
30
     */
31 4
    public static function emit()
32
    {
33 4
        return call_user_func_array([static::$events, 'emit'], func_get_args());
34
    }
35
36
    /**
37
     * Emit event.
38
     *
39
     * @param  string $event
40
     * @param  ListenerInterface|callable $listener
41
     * @return EventInterface|string
42
     */
43 1
    public static function on($event, $listener)
44
    {
45 1
        return static::$events->addListener($event, $listener);
46
    }
47
48
    /**
49
     * Remove listeners.
50
     *
51
     * @param $event
52
     */
53 1
    public static function off($event)
54
    {
55 1
        static::$events->removeAllListeners($event);
56 1
    }
57
}
58