SimpleListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 32
rs 10
c 1
b 0
f 1
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 3 1
A invoked() 0 4 2
A __invoke() 0 3 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