Proxy::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Monooso\Unobserve;
4
5
use BadMethodCallException;
6
7
class Proxy
8
{
9
    /** @var object */
10
    private $target;
11
12
    /** @var array */
13
    private $events;
14
15 9
    public function __construct($target, array $events = [])
16
    {
17 9
        $this->target = $target;
18 9
        $this->events = $events;
19 9
    }
20
21 7
    public function __call($name, $arguments)
22
    {
23 7
        if ($this->isMuted($name)) {
24 5
            return null;
25
        }
26
27 4
        if (method_exists($this->target, $name)) {
28 3
            return $this->target->$name(...$arguments);
29
        }
30
31 1
        throw new BadMethodCallException(sprintf(
32 1
            'Unknown method [%s@%s]',
33 1
            get_class($this->target),
34
            $name
35
        ));
36
    }
37
38 7
    protected function isMuted($name): bool
39
    {
40 7
        return (in_array('*', $this->events) || in_array($name, $this->events));
41
    }
42
}
43