AsyncEventEmitterTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 53
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A attachOnListener() 0 9 1
A attachOnceListener() 0 11 1
A attachTimesListener() 0 16 2
1
<?php
2
3
namespace Dazzle\Event;
4
5
use Dazzle\Loop\LoopAwareTrait;
6
7
trait AsyncEventEmitterTrait
8
{
9
    use LoopAwareTrait;
10
    use BaseEventEmitterTrait;
11
12
    /**
13
     * @see BaseEventEmitterTrait::attachOnListener
14
     */
15 28
    protected function attachOnListener($pointer, $event, callable $listener)
0 ignored issues
show
Unused Code introduced by
The parameter $pointer is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
    {
17
        return function() use($listener) {
18 20
            $args = func_get_args();
19
            $this->getLoop()->onTick(function() use($listener, $args) {
20 20
                $listener(...$args);
21 20
            });
22 28
        };
23
    }
24
25
    /**
26
     * @see BaseEventEmitterTrait::attachOnceListener
27
     */
28 6
    protected function attachOnceListener($pointer, $event, callable $listener)
29
    {
30
        return function() use($listener, $event, $pointer) {
31 6
            unset($this->eventListeners[$event][$pointer]);
32
33 6
            $args = func_get_args();
34
            $this->getLoop()->onTick(function() use($listener, $args) {
35 6
                $listener(...$args);
36 6
            });
37 6
        };
38
    }
39
40
    /**
41
     * @see BaseEventEmitterTrait::attachTimesListener
42
     */
43 14
    protected function attachTimesListener($pointer, $event, $limit, callable $listener)
44
    {
45 14
        $emitter = $this;
46
        return function() use($emitter, $listener, $event, $pointer, &$limit) {
47 14
            if (--$limit === 0)
48
            {
49 14
                unset($limit);
50 14
                unset($emitter->eventListeners[$event][$pointer]);
51
            }
52
53 14
            $args = func_get_args();
54 14
            $this->getLoop()->onTick(function() use($listener, $args) {
55 14
                $listener(...$args);
56 14
            });
57 14
        };
58
    }
59
}
60