Completed
Push — develop ( 98dd0e...37ae8a )
by Stéphane
02:08
created

LeagueEventAdapter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 48
ccs 10
cts 12
cp 0.8333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add() 0 5 1
A remove() 0 5 1
A get() 0 10 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 2016
8
 * @author Stephane HULARD <[email protected]>
9
 */
10
11
namespace Bee4\Events\Adapters;
12
13
use League\Event\Emitter;
14
use League\Event\CallbackListener;
15
16
/**
17
 * Bridge to the PHP League Event implementation
18
 * @see http://event.thephpleague.com/2.0/
19
 */
20
class LeagueEventAdapter extends AbstractDispatcherAdapter
21
{
22
    /**
23
     * Adapted emitter
24
     * @var Emitter
25
     */
26
    protected $emitter;
27
28
    /**
29
     * @param Emitter $emitter
30
     */
31
    public function __construct(Emitter $emitter)
32
    {
33
        $this->emitter = $emitter;
34
    }
35
36
    /**
37
     * @see AbstractDispatcherAdapter::add
38
     */
39
    public function add($name, callable $listener, $priority = 0)
40
    {
41 1
        $this->emitter->addListener($name, $listener, $priority);
42 1
        return $this;
43
    }
44
45
    /**
46
     * @see AbstractDispatcherAdapter::remove
47
     */
48
    public function remove($name, callable $listener)
49
    {
50 1
        $this->emitter->removeListener($name, $listener);
51 1
        return $this;
52
    }
53
54
    /**
55
     * @see AbstractDispatcherAdapter::get
56
     */
57
    public function get($name)
58
    {
59 1
        return array_map(
60 1
            function (CallbackListener $listener) {
61 1
                return $listener->getCallback();
62 1
            },
63 1
            $this->emitter->getListeners($name)
64 1
        );
65
66
    }
67
}
68