PlainTextEmitter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 38.71 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 12
loc 31
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 12 23 3
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 PlainTextEmitter extends AbstractHttpEmitter
10
{
11 4
    protected function format(Throwable $exception) : string
12
    {
13 4
        $text = sprintf(
14 4
            '%s: %s',
15 4
            get_class($exception),
16 4
            $exception->getMessage()
17
        );
18
19 4 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...
20 2
            $text .= "\n\n";
21
22 2
            $trace = $exception->getTrace();
23 2
            $traceLength = count($trace);
24
25 2
            $text .= "Stacktrace:\n";
26 2
            foreach ($trace as $i => $traceRecord) {
27 2
                $text .= $this->formatTraceRecord($traceRecord, $i, $traceLength);
28 2
                $text .= "\n";
29
            }
30
        }
31
32 4
        return $text;
33
    }
34
35 1
    protected function getContentType() : string
36
    {
37 1
        return 'text/plain';
38
    }
39
}
40