JsonEmitter::format()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CentErr\Emitter;
6
7
use Throwable;
8
9
final class JsonEmitter extends AbstractHttpEmitter
10
{
11 3
    protected function format(Throwable $exception) : string
12
    {
13
        $errorInfo = [
14 3
            'type' => get_class($exception),
15 3
            'message' => $exception->getMessage(),
16 3
            'file' => $exception->getFile(),
17 3
            'line' => $exception->getLine(),
18 3
            'trace' => $exception->getTrace(),
19
        ];
20
21 3
        return json_encode([
22 3
            'error' => $errorInfo,
23 3
        ], defined('JSON_PARTIAL_OUTPUT_ON_ERROR') ? JSON_PARTIAL_OUTPUT_ON_ERROR : 0);
24
    }
25
26 1
    protected function getContentType() : string
27
    {
28 1
        return 'application/json';
29
    }
30
}
31