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 — 3.x ( 854d93...81f322 )
by Jindřich
01:52
created

EventDispatcherTrait::subscribe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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