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

JsonConverter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convert() 0 6 1
A contentType() 0 3 1
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