AbstractEmitter::formatTraceRecord()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 1
nop 3
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CentErr\Emitter;
6
7
use Throwable;
8
9
abstract class AbstractEmitter implements EmitterInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    protected $options = [
15
        'includeTrace' => true,
16
    ];
17
18 12
    public function __construct(array $options = [])
19
    {
20 12
        $this->options = array_merge($this->options, $options);
21 12
    }
22
23 12
    public function emit(Throwable $exception) : void
24
    {
25 12
        ob_start();
26 12
        $output = $this->format($exception);
27 12
        ob_end_clean();
28
29 12
        echo $output;
30 12
    }
31
32
    abstract protected function format(Throwable $exception) : string;
33
34 5
    final protected function formatTraceRecord(array $traceRecord, int $index, int $traceLength) : string
35
    {
36 5
        return sprintf(
37 5
            '#%s %s%s%s in %s:%s',
38 5
            $traceLength - $index - 1,
39 5
            $traceRecord['class'] ?? '',
40 5
            isset($traceRecord['class'], $traceRecord['function']) ? ':' : '',
41 5
            $traceRecord['function'] ?? '',
42 5
            $traceRecord['file'] ?? 'unknown',
43 5
            $traceRecord['line'] ?? 0
44
        );
45
    }
46
}
47