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::dispatch()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 6
cp 0.8333
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.0416
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