GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — supported-php-versions ( b1e0a1 )
by
unknown
03:56
created

EventDispatcherTrait::subscribe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Skautis\EventDispatcher;
4
5
trait EventDispatcherTrait
6
{
7
8
    /** @var callable[] */
9
    private $listeners = [];
10
11
12
    /**
13
     * @param string|null $eventName
14
     * @return bool
15
     */
16
    protected function hasListeners($eventName = null)
17
    {
18
        return $eventName === null ? !empty($this->listeners) : !empty($this->listeners[$eventName]);
19
    }
20
21
    /**
22
     * @param string $eventName
23
     * @param mixed $data
24
     */
25
    protected function dispatch($eventName, $data)
26
    {
27
        if (!$this->hasListeners($eventName)) {
28
            return;
29
        }
30
31
        foreach ($this->listeners[$eventName] as $callback) {
32
            call_user_func($callback, $data);
33
        }
34
    }
35
36
    /**
37
     * @param string $eventName
38
     * @param callable $callback
39
     */
40
    public function subscribe($eventName, callable $callback)
41
    {
42
        $this->listeners[$eventName][] = $callback;
43
    }
44
}
45