SimpleListener::invoked()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace ByTIC\EventDispatcher\Tests\Fixtures\Listeners;
4
5
use ByTIC\EventDispatcher\Events\EventInterface;
6
use ByTIC\EventDispatcher\Listeners\ListenerInterface;
7
8
/**
9
 * Class SimpleListener
10
 * @package ByTIC\EventDispatcher\Tests\Fixtures\Listeners
11
 */
12
class SimpleListener implements ListenerInterface
13
{
14
    protected $events = [];
15
16
    /**
17
     * @param EventInterface $event
18
     */
19
    public function __invoke(EventInterface $event)
20
    {
21
        $this->handle($event);
22
    }
23
24
    /**
25
     * Handle an event.
26
     *
27
     * @param EventInterface $event
28
     *
29
     * @return void
30
     */
31
    public function handle(EventInterface $event)
32
    {
33
        $this->events[$event->getName()] = true;
34
    }
35
36
    /**
37
     * @param EventInterface|string $event
38
     * @return bool
39
     */
40
    public function invoked($event): bool
41
    {
42
        $name = is_object($event) ? $event->getName() : $event;
43
        return isset($this->events[$name]);
44
    }
45
}
46