Proxy   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 14 3
A isMuted() 0 3 2
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
    public function __construct($target, array $events = [])
16
    {
17
        $this->target = $target;
18
        $this->events = $events;
19
    }
20
21
    public function __call($name, $arguments)
22
    {
23
        if ($this->isMuted($name)) {
24
            return null;
25
        }
26
27
        if (method_exists($this->target, $name)) {
28
            return $this->target->$name(...$arguments);
29
        }
30
31
        throw new BadMethodCallException(sprintf(
32
            'Unknown method [%s@%s]',
33
            get_class($this->target),
34
            $name
35
        ));
36
    }
37
38
    protected function isMuted($name): bool
39
    {
40
        return (in_array('*', $this->events) || in_array($name, $this->events));
41
    }
42
}
43