Passed
Pull Request — master (#5)
by Samuel
03:45
created

JsonHandler   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 12
c 2
b 0
f 0
dl 0
loc 159
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A jsonResponse() 0 9 2
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