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
Pull Request — 2.x (#64)
by Jindřich
07:10
created

EventDispatcherTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 0
dl 0
loc 40
ccs 0
cts 17
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasListeners() 0 4 2
A dispatch() 0 10 3
A subscribe() 0 4 1
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