BaseException   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 16
dl 0
loc 43
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __toString() 0 8 1
A render() 0 12 1
1
<?php
2
3
namespace SoliDry\Exceptions;
4
5
use Illuminate\Http\JsonResponse;
6
use SoliDry\Extension\JSONApiInterface;
7
use SoliDry\Helpers\Json;
8
9
class BaseException extends \Exception
10
{
11
12
    /**
13
     * BaseException constructor.
14
     *
15
     * @param $message
16
     * @param int $code
17
     */
18
    public function __construct($message, $code = 0)
19
    {
20
        parent::__construct($message, $code);
21
    }
22
23
    public function __toString()
24
    {
25
        parent::__toString();
26
        return (new Json)->getErrors([
27
            'code'    => $this->getCode(),
28
            'message' => $this->getMessage(),
29
            'file'    => $this->getFile(),
30
            'line'    => $this->getLine(),
31
        ]);
32
    }
33
34
    /**
35
     * Render the exception into an HTTP response.
36
     *
37
     * @param  \Illuminate\Http\Request $request
38
     * @return JsonResponse
39
     */
40
    public function render($request) : JsonResponse
41
    {
42
        return response()->json(
43
            [
44
                JSONApiInterface::CONTENT_ERRORS => [
45
                    [
46
                        'code'    => $this->getCode(),
47
                        'message' => $this->getMessage(),
48
                        'file'    => $this->getFile(),
49
                        'line'    => $this->getLine(),
50
                        'uri'     => $request->getUri(),
51
                        'meta'    => $this->getTraceAsString(),
52
                    ],
53
                ]
54
            ]
55
        );
56
    }
57
}
58