HtmlEmitter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 29.55 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 13
loc 44
ccs 20
cts 24
cp 0.8333
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 8 1
B doFormat() 13 27 4
A getContentType() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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