Test Failed
Pull Request — master (#133)
by Rustam
03:14
created

ServiceMethodProxy   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 31
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A afterCall() 0 12 2
A getNewStaticInstance() 0 3 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
    private array $methods;
12
13
    public function __construct(
14
        string $service,
15
        object $instance,
16
        array $methods,
17
        ContainerProxyConfig $config
18
    ) {
19
        $this->methods = $methods;
20
        parent::__construct($service, $instance, $config);
21
    }
22
23
    protected function afterCall(string $methodName, array $arguments, mixed $result, float $timeStart): mixed
24
    {
25
        try {
26
            if (isset($this->methods[$methodName])) {
27
                $callback = $this->methods[$methodName];
28
                $result = $callback($result, ...$arguments);
29
            }
30
        } finally {
31
            $this->logProxy($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