CommandLineEmitter::format()   B
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 28
Code Lines 17

Duplication

Lines 12
Ratio 42.86 %

Code Coverage

Tests 17
CRAP Score 3

Importance

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