JsonEmitter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 14 2
A getContentType() 0 4 1
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