Stacktrace   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 35
ccs 15
cts 15
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getDebugBacktrace() 0 25 5
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Helper;
4
5
use ZoiloMora\ElasticAPM\Events\Common\StacktraceFrame;
6
7
final class Stacktrace
8
{
9
    /**
10
     * Function to convert debug_backtrace results to an array of stack frames
11
     *
12
     * @param int $limit
13
     * @param int $skip
14
     *
15
     * @return array|null
16
     */
17 6
    public static function getDebugBacktrace($limit = 4, $skip = 1)
18
    {
19 6
        if (0 === $limit) {
20 5
            return null;
21
        }
22
23 1
        $debugBacktrace = array_slice(
24 1
            debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT),
25
            $skip
26 1
        );
27
28 1
        $stacktraceFrames = [];
29 1
        foreach ($debugBacktrace as $trace) {
30 1
            if (false === array_key_exists('file', $trace)) {
31 1
                continue;
32
            }
33
34 1
            $stacktraceFrames[] = StacktraceFrame::fromDebugBacktrace($trace);
35
36 1
            if ($limit === count($stacktraceFrames)) {
37 1
                break;
38
            }
39 1
        }
40
41 1
        return $stacktraceFrames;
42
    }
43
}
44