EventProfilerListener   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 2
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A attachShared() 0 4 1
A detachShared() 0 8 3
A onAnyEvent() 0 4 1
1
<?php
2
/**
3
 * Webino (http://webino.sk/)
4
 *
5
 * @link        https://github.com/webino/WebinoDebug/ for the canonical source repository
6
 * @copyright   Copyright (c) 2014-2017 Webino, s. r. o. (http://webino.sk/)
7
 * @license     BSD-3-Clause
8
 */
9
10
namespace WebinoDebug\Listener;
11
12
use WebinoDebug\Service\EventProfiler;
13
use Zend\EventManager\EventInterface;
14
use Zend\EventManager\SharedEventManagerInterface;
15
use Zend\EventManager\SharedListenerAggregateInterface;
16
17
/**
18
 * Class EventProfilerListener
19
 */
20
class EventProfilerListener implements SharedListenerAggregateInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Zend\EventManager\SharedListenerAggregateInterface has been deprecated with message: This interface is deprecated with 2.6.0, and will be removed in 3.0.0. See {@link https://github.com/zendframework/zend-eventmanager/blob/develop/doc/book/migration/removed.md} for details.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
21
{
22
    /**
23
     * Event highest priority
24
     */
25
    const HIGHEST_PRIORITY = 9999999999;
26
27
    /**
28
     * @var EventProfiler
29
     */
30
    protected $eventProfiler;
31
32
    /**
33
     * @var \Zend\Stdlib\CallbackHandler[]
34
     */
35
    protected $listeners = [];
36
37
    /**
38
     * @param object|EventProfiler $eventProfiler
39
     */
40
    public function __construct(EventProfiler $eventProfiler)
41
    {
42
        $this->eventProfiler = $eventProfiler;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function attachShared(SharedEventManagerInterface $events)
49
    {
50
        $this->listeners[] = $events->attach('*', '*', [$this, 'onAnyEvent'], self::HIGHEST_PRIORITY);
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function detachShared(SharedEventManagerInterface $events)
57
    {
58
        foreach ($this->listeners as $key => $listener) {
59
            if ($events->detach('*', '*', $listener)) {
0 ignored issues
show
Documentation introduced by
'*' is of type string, but the function expects a object<Zend\Stdlib\CallbackHandler>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to SharedEventManagerInterface::detach() has too many arguments starting with $listener.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
                unset($this->listeners[$key]);
61
            }
62
        }
63
    }
64
65
    /**
66
     * @param EventInterface $event
67
     */
68
    public function onAnyEvent(EventInterface $event)
69
    {
70
        $this->eventProfiler->setEvent($event);
71
    }
72
}
73