CommandLineEmitter   A
last analyzed

Complexity

Total Complexity 3

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 3
lcom 1
cbo 1
dl 12
loc 31
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B format() 12 28 3

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 CommandLineEmitter extends AbstractEmitter
10
{
11 2
    protected function format(Throwable $exception) : string
12
    {
13 2
        $headerText = ' AN ERROR HAS OCCURRED ';
14 2
        $border = str_repeat('-', strlen($headerText));
15
16 2
        $output = "+$border+\n|$headerText|\n+$border+\n";
17
18 2
        $output .= sprintf(
19 2
            '%s: %s',
20 2
            get_class($exception),
21 2
            $exception->getMessage()
22
        );
23
24 2 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 1
            $output .= "\n\n";
26
27 1
            $trace = $exception->getTrace();
28 1
            $traceLength = count($trace);
29
30 1
            $output .= "Stacktrace:\n";
31 1
            foreach ($trace as $i => $traceRecord) {
32 1
                $output .= $this->formatTraceRecord($traceRecord, $i, $traceLength);
33 1
                $output .= "\n";
34
            }
35
        }
36
37 2
        return $output;
38
    }
39
}
40