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.

EventContainer::hasEvent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace Thunder\Shortcode\EventContainer;
3
4
use Thunder\Shortcode\Events;
5
6
/**
7
 * @author Tomasz Kowalczyk <[email protected]>
8
 */
9
final class EventContainer implements EventContainerInterface
10
{
11
    /** @psalm-var array<string,list<callable>> */
12
    private $listeners = array();
13
14 9
    public function __construct()
15
    {
16 9
    }
17
18
    /**
19
     * @param string $event
20
     * @param callable $handler
21
     *
22
     * @return void
23
     */
24 5
    public function addListener($event, $handler)
25
    {
26 5
        if(!\in_array($event, Events::getEvents(), true)) {
27 1
            throw new \InvalidArgumentException(sprintf('Unsupported event %s!', $event));
28
        }
29
30 4
        if(!array_key_exists($event, $this->listeners)) {
31 4
            $this->listeners[$event] = array();
32 4
        }
33
34 4
        $this->listeners[$event][] = $handler;
35 4
    }
36
37
    /**
38
     * @param string $event
39
     *
40
     * @psalm-return list<callable>
41
     */
42 5
    public function getListeners($event)
43
    {
44 5
        return $this->hasEvent($event) ? $this->listeners[$event] : array();
45
    }
46
47
    /**
48
     * @param string $name
49
     *
50
     * @return bool
51
     */
52 5
    private function hasEvent($name)
53
    {
54 5
        return array_key_exists($name, $this->listeners);
55
    }
56
}
57