Passed
Pull Request — master (#5)
by Samuel
04:50 queued 01:39
created

JsonHandler::jsonResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SMartins\Exceptions;
4
5
use Exception;
6
use SMartins\Exceptions\Handlers\Handler;
7
8
trait JsonHandler
9
{
10
    /**
11
     * Handle the json response. Check if exception is treated. If true call
12
     * the specific handler. If false set the default response to be returned.
13
     *
14
     * @param  \Exception $exception
15
     *
16
     * @return \Illuminate\Http\JsonResponse
17
     */
18
    public function jsonResponse(Exception $exception)
19
    {
20
        $handler = new Handler($exception);
21
22
        if (property_exists($this, 'exceptionHandlers')) {
23
            $handler->setExceptionHandlers($this->exceptionHandlers);
24
        }
25
26
        return $handler->handleException()->json();
27
    }
28
}
29