Listener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Ariadne Component Library.
5
 *
6
 * (c) Muze <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace arc\events;
13
14
/**
15
 *	This object is returned for each event you listen for. It allows you to specifically remove
16
 *	that event listener.
17
 */
18
class Listener
19
{
20
    protected $capture    = false;
21
    protected $eventName  = '';
22
    protected $id         = null;
23
    protected $eventStack = null;
24
25
    /**
26
     *	@param string $eventName The name of the event
27
     *	@param int $id The id of this listener. This is unique for this eventStack.
28
     *	@param string $path Optional. The path listened on, defaults to '/'
0 ignored issues
show
Bug introduced by
There is no parameter named $path. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
29
     *	@param bool $capture Optional. True for capture phase listeners, default is false.
30
     *	@param Stack $eventStack Optional. The eventStack the listener is registered on. Must be set
31
     *		for remove() to work.
32
     */
33 12
    public function __construct($eventName, $id, $capture = false, $eventStack = null)
34
    {
35 12
        $this->eventName  = $eventName;
36 12
        $this->capture    = $capture;
37 12
        $this->id         = $id;
38 12
        $this->eventStack = $eventStack;
39 12
    }
40
41
    /**
42
     *	This method removes this listener from the eventStack. If a matching event is fired later,
43
     *	the corresponding listener callback will no longer be called.
44
     */
45 12
    public function remove()
46
    {
47 12
        if (isset($this->id)) {
48 12
            $this->eventStack->removeListener( $this->eventName, $this->id, $this->capture );
49 6
        }
50 12
    }
51
52
    /*
53
     *   This allows you to chain listeners and cd() calls on the eventtree.
54
     */
55
    public function __call($method, $args)
56
    {
57
        return call_user_func_array( [ $this->eventStack, $method ], $args );
58
    }
59
60
    /* TODO: add an add() method, which re-adds the listener, potentially as last in the list */
61
}
62