Tracer::trace()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 3
eloc 5
nc 4
nop 3
dl 0
loc 9
rs 9.6666
c 2
b 1
f 0
1
<?php
2
3
namespace PedroTroller\TraceDebug;
4
5
use Exception;
6
7
class Tracer
8
{
9
    /**
10
     * @var TraceHandler[]
11
     */
12
    private static $handlers = [];
13
14
    /**
15
     * Capture the current stacktrace.
16
     *
17
     * @param string|null $identifier
18
     */
19
    public static function trace($identifier = null, $subtrace = 1, Exception $exception = null)
20
    {
21
        $exception = null === $exception ? new Exception() : $exception;
22
        $trace     = array_slice($exception->getTrace(), $subtrace);
23
24
        foreach (self::$handlers as $handler) {
25
            $handler->onTrace($trace, $identifier);
26
        }
27
    }
28
29
    /**
30
     * @param TraceHandler $handler
31
     */
32
    public function addHandler(TraceHandler $handler)
33
    {
34
        self::$handlers[] = $handler;
35
    }
36
}
37