FakeDispatcher   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 5
Bugs 1 Features 0
Metric Value
wmc 7
c 5
b 1
f 0
lcom 1
cbo 0
dl 0
loc 47
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 12 4
A add() 0 6 1
A remove() 0 3 1
A get() 0 3 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 2015
8
 * @author Stephane HULARD <[email protected]>
9
 * @package Bee4\Test
10
 */
11
12
namespace Bee4\Test;
13
14
use Bee4\Events\DispatcherInterface;
15
use Bee4\Events\EventInterface;
16
17
/**
18
 * A basic dispatcher implementation that can be used for testing purpose
19
 * @package Bee4\Test
20
 */
21
class FakeDispatcher implements DispatcherInterface
22
{
23
    /**
24
     * Listener collection
25
     * @var array
26
     */
27
    protected $listeners = [];
28
29
    /**
30
     * @param string $name
31
     * @param EventInterface $event
32
     * @return EventInterface
33
     */
34
    public function dispatch($name, EventInterface $event)
35
    {
36
        if (isset($this->listeners[$name])) {
37
            foreach ($this->listeners[$name] as $priority) {
38
                foreach ($priority as $callable) {
39
                    call_user_func($callable, $event, $name, $this);
40
                }
41
            }
42
        }
43
44
        return $event;
45
    }
46
47
    /**
48
     * Add a listener for the given event
49
     * @param string $name
50
     * @param Callable $listener
51
     * @param int $priority
52
     * @return DispatcherInterface
53
     */
54
    public function add($name, callable $listener, $priority = 0)
55
    {
56
        $this->listeners[$name][$priority][] = $listener;
57
        sort($this->listeners[$name]);
58
        return $this;
59
    }
60
61
    public function remove($name, callable $listener)
62
    {
63
    }
64
    public function get($name)
65
    {
66
    }
67
}
68