Handler   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 18
c 1
b 0
f 0
dl 0
loc 64
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 7 2
A report() 0 8 4
A unauthenticated() 0 7 2
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Auth\AuthenticationException;
7
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10
class Handler extends ExceptionHandler
11
{
12
    /**
13
     * A list of the exception types that should not be reported.
14
     *
15
     * @var array
16
     */
17
    protected $dontReport = [
18
        \Illuminate\Auth\AuthenticationException::class,
19
        \Illuminate\Auth\Access\AuthorizationException::class,
20
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
21
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
22
        \Illuminate\Session\TokenMismatchException::class,
23
        \Illuminate\Validation\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  $exception
32
     * @return void
33
     */
34
    public function report(Exception $exception)
35
    {
36
        if (!app()->environment('local') && app()->bound('sentry') &&
0 ignored issues
show
introduced by
The method environment() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        if (!app()->/** @scrutinizer ignore-call */ environment('local') && app()->bound('sentry') &&
Loading history...
37
            $this->shouldReport($exception)) {
38
            app('sentry')->captureException($exception);
39
        }
40
41
        parent::report($exception);
42
    }
43
44
    /**
45
     * Render an exception into an HTTP response.
46
     *
47
     * @param  \Illuminate\Http\Request  $request
48
     * @param  \Exception  $exception
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function render($request, Exception $exception)
52
    {
53
        if (!app()->environment('local')) {
54
            return response()->view('errors.500', [], 500);
55
        }
56
57
        return parent::render($request, $exception);
58
    }
59
60
    /**
61
     * Convert an authentication exception into an unauthenticated response.
62
     *
63
     * @param  \Illuminate\Http\Request  $request
64
     * @param  \Illuminate\Auth\AuthenticationException  $exception
65
     * @return \Illuminate\Http\Response
66
     */
67
    protected function unauthenticated($request, AuthenticationException $exception)
68
    {
69
        if ($request->expectsJson()) {
70
            return response()->json(['error' => 'Unauthenticated.'], 401);
71
        }
72
73
        return redirect()->guest('login');
74
    }
75
}
76