Invoker::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Dazzle\Util\Invoker;
4
5
class Invoker implements InvokerInterface
6
{
7
    /**
8
     * @var callable[]
9
     */
10
    protected $proxies;
11
12
    /**
13
     * @param callable[] $proxies
14
     */
15 10
    public function __construct($proxies = [])
16
    {
17 10
        $this->proxies = [];
18
19 10
        foreach ($proxies as $func=>$proxy)
20
        {
21 1
            $this->setProxy($func, $proxy);
22
        }
23 10
    }
24
25
    /**
26
     *
27
     */
28 10
    public function __destruct()
29
    {
30 10
        unset($this->proxies);
31 10
    }
32
33
    /**
34
     * @override
35
     * @inheritDoc
36
     */
37 2
    public function call($func, $args = [])
38
    {
39 2
        return call_user_func_array($this->getProxy($func), $args);
40
    }
41
42
    /**
43
     * @override
44
     * @inheritDoc
45
     */
46 5
    public function existsProxy($func)
47
    {
48 5
        return isset($this->proxies[$func]);
49
    }
50
51
    /**
52
     * @override
53
     * @inheritDoc
54
     */
55 6
    public function setProxy($func, $callable)
56
    {
57 6
        $this->proxies[$func] = $callable;
58 6
    }
59
60
    /**
61
     * @override
62
     * @inheritDoc
63
     */
64 1
    public function removeProxy($func)
65
    {
66 1
        unset($this->proxies[$func]);
67 1
    }
68
69
    /**
70
     * @override
71
     * @inheritDoc
72
     */
73 3
    public function getProxy($func)
74
    {
75 3
        return isset($this->proxies[$func]) ? $this->proxies[$func] : $func;
76
    }
77
}
78