Proxy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 34
ccs 14
cts 14
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isMuted() 0 3 2
A __call() 0 14 3
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