Passed
Push — master ( b3236d...aac68f )
by Alexander
04:13
created

ServiceMethodProxy::afterCall()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 5
nop 4
dl 0
loc 12
ccs 5
cts 7
cp 0.7143
crap 2.0932
rs 10
c 0
b 0
f 0
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 2
    public function __construct(
14
        string $service,
15
        object $instance,
16
        array $methods,
17
        ContainerProxyConfig $config
18
    ) {
19 2
        $this->methods = $methods;
20 2
        parent::__construct($service, $instance, $config);
21
    }
22
23 1
    protected function afterCall(string $methodName, array $arguments, mixed $result, float $timeStart): mixed
24
    {
25
        try {
26 1
            if (isset($this->methods[$methodName])) {
27
                $callback = $this->methods[$methodName];
28
                $result = $callback($result, ...$arguments);
29
            }
30 1
        } finally {
31 1
            $this->logProxy($this->getService(), $this->getInstance(), $methodName, $arguments, $result, $timeStart);
32
        }
33
34 1
        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