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 (#78)
by Jindřich
02:01
created

EventDispatcherTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90.91%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasListeners() 0 4 2
A subscribe() 0 4 1
A dispatch() 0 10 3
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 2
    protected function hasListeners($eventName = null)
17
    {
18 2
        return $eventName === null ? !empty($this->listeners) : !empty($this->listeners[$eventName]);
19
    }
20
21
    /**
22
     * @param string $eventName
23
     * @param mixed $data
24
     */
25 2
    protected function dispatch($eventName, $data)
26
    {
27 2
        if (!$this->hasListeners($eventName)) {
28
            return;
29
        }
30
31 2
        foreach ($this->listeners[$eventName] as $callback) {
32 2
            call_user_func($callback, $data);
33
        }
34 2
    }
35
36
    /**
37
     * @param string $eventName
38
     * @param callable $callback
39
     */
40 2
    public function subscribe($eventName, callable $callback)
41
    {
42 2
        $this->listeners[$eventName][] = $callback;
43 2
    }
44
}
45