VarDumperHandlerInterfaceProxy   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 25 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Yiisoft\VarDumper\HandlerInterface;
8
9
final class VarDumperHandlerInterfaceProxy implements HandlerInterface
10
{
11
    public function __construct(
12
        private readonly HandlerInterface $decorated,
13
        private readonly VarDumperCollector $collector,
14
    ) {
15
    }
16
17
    public function handle(mixed $variable, int $depth, bool $highlight = false): void
18
    {
19
        $stack = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
20
21
        $callStack = null;
22
        foreach ($stack as $value) {
23
            if (!isset($value['file'])) {
24
                continue;
25
            }
26
            if (str_ends_with($value['file'], '/var-dumper/src/functions.php')) {
27
                continue;
28
            }
29
            if (str_ends_with($value['file'], '/var-dumper/src/VarDumper.php')) {
30
                continue;
31
            }
32
            $callStack = $value;
33
            break;
34
        }
35
        /** @psalm-var array{file: string, line: int}|null $callStack */
36
37
        $this->collector->collect(
38
            $variable,
39
            $callStack === null ? '' : $callStack['file'] . ':' . $callStack['line']
40
        );
41
        $this->decorated->handle($variable, $depth, $highlight);
42
    }
43
}
44