Test Failed
Pull Request — master (#93)
by Dmitriy
02:52
created

DebugHandlerInterfaceProxy::handle()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 15
nc 5
nop 3
dl 0
loc 24
rs 9.2222
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\VarDumper\Debug;
6
7
use Yiisoft\VarDumper\HandlerInterface;
8
9
final class DebugHandlerInterfaceProxy implements HandlerInterface
10
{
11
    public function __construct(
12
        private HandlerInterface $decorated,
13
        private 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
36
        $this->collector->collectVar(
37
            $variable,
38
            $callStack === null ? '' : $callStack['file'] . ':' . $callStack['line']
39
        );
40
        $this->decorated->handle($variable, $depth, $highlight);
41
    }
42
}
43