ServiceMethodProxy::getNewStaticInstance()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.2963

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 6
ccs 1
cts 3
cp 0.3333
crap 1.2963
rs 10
c 0
b 0
f 0
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