CallbackListener::fromCallable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace ByTIC\EventDispatcher\Listeners;
4
5
use ByTIC\EventDispatcher\Events\EventInterface;
6
7
/**
8
 * Class CallbackListener
9
 * @package ByTIC\EventDispatcher\Listeners
10
 */
11
class CallbackListener implements ListenerInterface
12
{
13
    /**
14
     * The callback.
15
     *
16
     * @var callable
17
     */
18
    protected $callback;
19
20
    /**
21
     * Create a new callback listener instance.
22
     *
23
     * @param callable $callback
24
     */
25
    final public function __construct(callable $callback)
26
    {
27
        $this->callback = $callback;
28
    }
29
30
    /**
31
     * @inheritdoc
32
     */
33
    public function handle(EventInterface $event)
34
    {
35
        call_user_func_array($this->callback, func_get_args());
36
    }
37
38
    /**
39
     * Named constructor
40
     *
41
     * @param callable $callable
42
     *
43
     * @return static
44
     */
45
    public static function fromCallable(callable $callable)
46
    {
47
        return new static($callable);
48
    }
49
}
50