Completed
Push — master ( 40b08d...be8dcd )
by Stéphane
06:09
created

AbstractDispatcherAdapter::once()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 6
cts 6
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of the bee4/events package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 *
7
 * @copyright Bee4 2014
8
 * @author Stephane HULARD <[email protected]>
9
 * @package Bee4\Events\Adapters
10
 */
11
12
namespace Bee4\Events\Adapters;
13
14
use Bee4\Events\DispatcherInterface;
15
use Bee4\Events\EventInterface;
16
17
/**
18
 * Bridge to the Symfony EventDispatcher implementation
19
 * @package BeeBot\Event\Adapters
20
 */
21
abstract class AbstractDispatcherAdapter implements DispatcherInterface
22
{
23
    /**
24
     * Adapted instance
25
     */
26
    protected $dispatcher;
27
28
    /**
29
     * @see DispatcherInterface::dispatch
30
     * @param string $name
31
     * @param EventInterface $event
32
     * @return EventInterface
33
     */
34
    public function dispatch($name, EventInterface $event)
35
    {
36 1
        $listeners = $this->get($name);
37 1
        foreach ($listeners as $listener) {
38 1
            call_user_func($listener, $event, $name, $this);
39 1
        }
40
41 1
        return $event;
42
    }
43
44
    /**
45
     * @see DispatcherInterface::add
46
     * @param string   $name
47
     * @param callable $listener
48
     * @param integer  $priority
49
     * @deprecated
50
     */
51
    public function add($name, callable $listener, $priority = 0)
52
    {
53
        return $this->on($name, $listener);
54
    }
55
56
    /**
57
     * @see DispatcherInterface::on
58
     * @param string $name
59
     * @param Callable $listener
60
     * @param int $priority
0 ignored issues
show
Bug introduced by
There is no parameter named $priority. 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...
61
     * @return DispatcherInterface
62
     */
63
    abstract public function on($name, callable $listener);
64
65
    /**
66
     * @see DispatcherInterface::once
67
     * @param string $name
68
     * @param Callable $listener
69
     * @param int $priority
0 ignored issues
show
Bug introduced by
There is no parameter named $priority. 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...
70
     * @return DispatcherInterface
71
     */
72
    public function once($name, callable $listener)
73
    {
74 1
        $once = function() use (&$once, $name, $listener) {
75 1
            $this->remove($name, $once);
76 1
            call_user_func_array($listener, func_get_args());
77 1
        };
78 1
        $this->on($name, $once);
79 1
    }
80
81
    /**
82
     * @see DispatcherInterface::remove
83
     * @param string $name
84
     * @param Callable $listener
85
     * @return DispatcherInterface
86
     */
87
    abstract public function remove($name, callable $listener);
88
89
    /**
90
     * @see DispatcherInterface::get
91
     * @param string $name
92
     * @return array
93
     */
94
    abstract public function get($name);
95
}
96