HtmlEmitter::doFormat()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 27
Code Lines 17

Duplication

Lines 13
Ratio 48.15 %

Code Coverage

Tests 13
CRAP Score 4.2084

Importance

Changes 0
Metric Value
dl 13
loc 27
ccs 13
cts 17
cp 0.7647
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 17
nc 4
nop 1
crap 4.2084
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CentErr\Emitter;
6
7
use Throwable;
8
9
final class HtmlEmitter extends AbstractHttpEmitter
10
{
11 3
    protected function format(Throwable $exception) : string
12
    {
13 3
        $html = '<h2>An error has occurred</h2>';
14 3
        $html .= "\n";
15 3
        $html .= $this->doFormat($exception);
16
17 3
        return $html;
18
    }
19
20 3
    private function doFormat(Throwable $exception)
21
    {
22 3
        $html = '<p>' . $exception->getMessage() . '</p>';
23
24 3 View Code Duplication
        if ($this->options['includeTrace']) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25 2
            $html .= "\n";
26 2
            $html .= '<strong>Trace:</strong><br>';
27 2
            $html .= "\n";
28
29 2
            $trace = $exception->getTrace();
30 2
            $traceLength = count($trace);
31
32 2
            foreach ($exception->getTrace() as $i => $traceRecord) {
33 2
                $html .= "\n";
34 2
                $html .= $this->formatTraceRecord($traceRecord, $i, $traceLength) . '<br>';
35
            }
36
        }
37
38 3
        if ($previous = $exception->getPrevious()) {
39
            $html .= "\n";
40
            $html .= '<br><strong>Previous:</strong><br>';
41
            $html .= "\n";
42
            $html .= $this->doFormat($previous);
43
        }
44
45 3
        return $html;
46
    }
47
48 1
    protected function getContentType() : string
49
    {
50 1
        return 'text/html';
51
    }
52
}
53