Passed
Pull Request — master (#2)
by Alexander
01:11
created

Proxy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __unset() 0 4 1
A __isset() 0 4 1
A __set() 0 4 1
A __get() 0 4 1
A __construct() 0 4 1
A __call() 0 4 1
1
<?php
2
3
4
namespace Yiisoft\Proxy;
5
6
7
final class Proxy
8
{
9
    private object $proxied;
10
    private ProxyHandlerInterface $handler;
11
12 4
    public function __construct(object $proxied, ProxyHandlerInterface $handler)
13
    {
14 4
        $this->proxied = $proxied;
15 4
        $this->handler = $handler;
16 4
    }
17
18 1
    public function __get(string $name)
19
    {
20 1
        $this->handler->onGet($name, $this->proxied);
21 1
        return $this->proxied->$name;
22
    }
23
24 1
    public function __set(string $name, $value)
25
    {
26 1
        $this->handler->onSet($name, $value, $this->proxied);
27 1
        $this->proxied->$name = $value;
28 1
    }
29
30
    public function __isset(string $name)
31
    {
32
        $this->handler->onIsset($name);
0 ignored issues
show
Bug introduced by
The call to Yiisoft\Proxy\ProxyHandlerInterface::onIsset() has too few arguments starting with object. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $this->handler->/** @scrutinizer ignore-call */ 
33
                        onIsset($name);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
33
        return isset($this->proxied->$name);
34
    }
35
36
    public function __unset(string $name)
37
    {
38
        $this->handler->onUnset($name, $this->proxied);
39
        unset($this->proxied->$name);
40
    }
41
42 2
    public function __call(string $name, array $arguments)
43
    {
44 2
        $this->handler->onCall($name, $arguments, $this->proxied);
45 2
        $this->proxied->$name(...$arguments);
46 2
    }
47
}
48