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   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
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 31
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 dispatch() 0 10 3
A subscribe() 0 4 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