Completed
Branch master (bb48cc)
by vijay
148:50 queued 92:39
created

Handler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 5
c 3
b 1
f 0
lcom 0
cbo 2
dl 0
loc 64
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 3 1
A render() 0 13 2
A renderException() 0 13 2
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Auth\Access\AuthorizationException;
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
9
use Illuminate\Foundation\Validation\ValidationException;
10
use Symfony\Component\HttpKernel\Exception\HttpException;
11
12
class Handler extends ExceptionHandler {
13
14
    /**
15
     * A list of the exception types that should not be reported.
16
     *
17
     * @var array
18
     */
19
    protected $dontReport = [
20
        AuthorizationException::class,
21
        HttpException::class,
22
        ModelNotFoundException::class,
23
        ValidationException::class,
24
    ];
25
26
    /**
27
     * Report or log an exception.
28
     *
29
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
30
     *
31
     * @param \Exception $e
32
     *
33
     * @return void
34
     */
35
    public function report(Exception $e) {
36
        return parent::report($e);
37
    }
38
39
    /**
40
     * Render an exception into an HTTP response.
41
     *
42
     * @param \Illuminate\Http\Request $request
43
     * @param \Exception               $e
44
     *
45
     * @return \Illuminate\Http\Response
46
     */
47
    public function render($request, Exception $e) {
48
        switch ($e) {
49
50
            case ($e instanceof ModelNotFoundException):
51
52
                return $this->renderException($e);
53
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
54
55
            default:
56
57
                return parent::render($request, $e);
58
        }
59
    }
60
61
    protected function renderException($e) {
62
63
        switch ($e) {
64
65
            case ($e instanceof ModelNotFoundException):
66
                return redirect('/')->with('fails',"Please configure ". $e->getMessage());
67
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
68
69
            default:
70
                return (new SymfonyDisplayer(config('app.debug')))
71
                                ->createResponse($e);
72
        }
73
    }
74
75
}
76