ServiceMethodProxy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 31
ccs 8
cts 12
cp 0.6667
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A afterCall() 0 12 2
A getNewStaticInstance() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Yiisoft\Proxy\ObjectProxy;
8
9
class ServiceMethodProxy extends ServiceProxy
10
{
11
    public function __construct(
12
        string $service,
13 2
        object $instance,
14
        private readonly array $methods,
15
        ContainerProxyConfig $config
16
    ) {
17
        parent::__construct($service, $instance, $config);
18
    }
19 2
20 2
    protected function afterCall(string $methodName, array $arguments, mixed $result, float $timeStart): mixed
21
    {
22
        try {
23 1
            if (isset($this->methods[$methodName])) {
24
                $callback = $this->methods[$methodName];
25
                $result = $callback($result, ...$arguments);
26 1
            }
27
        } finally {
28
            $this->logProxy($this->getService(), $this->getInstance(), $methodName, $arguments, $result, $timeStart);
29
        }
30 1
31 1
        return $result;
32
    }
33
34 1
    protected function getNewStaticInstance(object $instance): ObjectProxy
35
    {
36
        /**
37
         * @psalm-suppress UnsafeInstantiation Constructor should be consistent to `getNewStaticInstance()`.
38
         */
39
        return new static($this->getService(), $instance, $this->methods, $this->getConfig());
40
    }
41
}
42