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

Proxy::__get()   A

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
eloc 2
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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