Completed
Push — master ( fc96a9...ebe14f )
by
unknown
04:28
created

ExceptionToJsonRenderer::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Kartenmacherei\RestFramework\Exception;
3
4
class ExceptionToJsonRenderer implements ExceptionRenderer
5
{
6
    /**
7
     * @param $throwable
8
     *
9
     * @return string
10
     */
11
    public function render(\Throwable $throwable): string
12
    {
13
        return $this->toJson($throwable);
14
    }
15
16
    /**
17
     * @param \Throwable $throwable
18
     * @return string
19
     */
20
    private function toJson(\Throwable $throwable): string
21
    {
22
        return json_encode(
23
            [
24
                'class' => get_class($throwable),
25
                'message' => $throwable->getMessage(),
26
                'file' => $throwable->getFile(),
27
                'line' => $throwable->getLine()
28
            ]
29
        );
30
    }
31
}
32