Tracer::addHandler()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
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