Stacktrace::getDebugBacktrace()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 2
b 0
f 0
nc 5
nop 2
dl 0
loc 25
ccs 15
cts 15
cp 1
crap 5
rs 9.5222
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