Passed
Push — main ( 33d492...e44212 )
by Filipe
12:02
created

JsonConverter::convert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Cors
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\Cors\Infrastructure\Converter;
13
14
use Slick\Cors\Infrastructure\Converter;
15
use Slick\ErrorHandler\Exception\ExceptionInspector;
16
use Throwable;
17
18
/**
19
 * JsonConverter
20
 *
21
 * @package Slick\Cors\Infrastructure\Converter
22
 */
23
final class JsonConverter implements Converter
24
{
25
26
    use JsonMethods;
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function convert(Throwable $throwable): string
32
    {
33
        $inspector = new ExceptionInspector($throwable);
34
        return json_encode([
35
            "error" => $this->clearTitle($throwable),
36
            "details" => $this->details($throwable, $inspector)
37
        ]);
38
    }
39
40
    /**
41
     * @inheritDoc
42
     */
43
    public function contentType(): string
44
    {
45
        return 'application/json';
46
    }
47
}
48