Passed
Pull Request — master (#74)
by Rustam
02:43
created

ServiceMethodProxy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 8
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Proxy;
6
7
use Yiisoft\Proxy\ObjectProxy;
8
9
class ServiceMethodProxy extends ServiceProxy
10
{
11
    private array $methods;
12
13 1
    public function __construct(
14
        string $service,
15
        object $instance,
16
        array $methods,
17
        ContainerProxyConfig $config
18
    ) {
19 1
        $this->methods = $methods;
20 1
        parent::__construct($service, $instance, $config);
21 1
    }
22
23
    protected function executeMethodProxy(string $methodName, array $arguments, $result, float $timeStart)
24
    {
25
        try {
26
            if (isset($this->methods[$methodName])) {
27
                $callback = $this->methods[$methodName];
28
                $result = $callback($result, ...$arguments);
29
            }
30
        } finally {
31
            $this->log($this->getService(), $this->getInstance(), $methodName, $arguments, $result, $timeStart);
32
        }
33
34
        return $result;
35
    }
36
37
    protected function getNewStaticInstance(object $instance): ObjectProxy
38
    {
39
        return new static($this->getService(), $instance, $this->methods, $this->getConfig());
40
    }
41
}
42