Passed
Pull Request — master (#21)
by
unknown
02:16
created

ObjectProxy   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 51
ccs 22
cts 22
cp 1
rs 10
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A callInternal() 0 3 1
A __construct() 0 3 1
A processResult() 0 7 3
A call() 0 14 2
A getInstance() 0 3 1
A getNewStaticInstance() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Proxy;
6
7
use Exception;
8
9
abstract class ObjectProxy
10
{
11
    use ProxyTrait;
12
13
    private object $instance;
14
15 7
    public function __construct(object $instance)
16
    {
17 7
        $this->instance = $instance;
18
    }
19
20 1
    public function getInstance(): object
21
    {
22 1
        return $this->instance;
23
    }
24
25 6
    protected function call(string $methodName, array $arguments)
26
    {
27 6
        $this->resetCurrentError();
28 6
        $result = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
29 6
        $timeStart = microtime(true);
30
        try {
31 6
            $result = $this->callInternal($methodName, $arguments);
32 3
        } catch (Exception $e) {
33 3
            $this->repeatError($e);
34 3
        } finally {
35 6
            $result = $this->executeMethodProxy($methodName, $arguments, $result, $timeStart);
0 ignored issues
show
Bug introduced by
It seems like $timeStart can also be of type string; however, parameter $timeStart of Yiisoft\Proxy\ObjectProxy::executeMethodProxy() does only seem to accept double, maybe add an additional type check? ( Ignorable by Annotation )

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

35
            $result = $this->executeMethodProxy($methodName, $arguments, $result, /** @scrutinizer ignore-type */ $timeStart);
Loading history...
36
        }
37
38 3
        return $this->processResult($result);
39
    }
40
41
    abstract protected function executeMethodProxy(string $methodName, array $arguments, $result, float $timeStart);
42
43 1
    protected function getNewStaticInstance(object $instance): self
44
    {
45 1
        return new static($instance);
46
    }
47
48 6
    private function callInternal(string $methodName, array $arguments)
49
    {
50 6
        return $this->instance->$methodName(...$arguments);
51
    }
52
53 3
    private function processResult($result)
54
    {
55 3
        if (is_object($result) && get_class($result) === get_class($this->instance)) {
56 1
            $result = $this->getNewStaticInstance($result);
57
        }
58
59 3
        return $result;
60
    }
61
}
62