HtmlEmitter::getContentType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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