Handler::report()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Auth\Access\AuthorizationException;
7
use Illuminate\Auth\AuthenticationException;
8
use Illuminate\Database\Eloquent\ModelNotFoundException;
9
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
10
use Illuminate\Session\TokenMismatchException;
11
use Illuminate\Validation\ValidationException;
12
use Symfony\Component\HttpKernel\Exception\HttpException;
13
14
class Handler extends ExceptionHandler
15
{
16
    /**
17
     * A list of the exception types that are not reported.
18
     *
19
     * @var array
20
     */
21
    protected $dontReport = [
22
        AuthenticationException::class,
23
        AuthorizationException::class,
24
        HttpException::class,
25
        ModelNotFoundException::class,
26
        TokenMismatchException::class,
27
        ValidationException::class,
28
    ];
29
30
    /**
31
     * A list of the inputs that are never flashed for validation exceptions.
32
     *
33
     * @var array
34
     */
35
    protected $dontFlash = [
36
        'password',
37
        'password_confirmation',
38
    ];
39
40
    /**
41
     * Report or log an exception.
42
     *
43
     * @param \Exception $exception
44
     *
45
     * @return void
46
     */
47
    public function report(Exception $exception)
48
    {
49
        if (app()->bound('sentry') && $this->shouldReport($exception)) {
50
            app('sentry')->captureException($exception);
0 ignored issues
show
Bug introduced by
The method captureException() does not exist on Illuminate\Contracts\Foundation\Application. ( Ignorable by Annotation )

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

50
            app('sentry')->/** @scrutinizer ignore-call */ captureException($exception);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
51
        }
52
53
        parent::report($exception);
54
    }
55
56
    /**
57
     * Render an exception into an HTTP response.
58
     *
59
     * @param \Illuminate\Http\Request $request
60
     * @param \Exception               $exception
61
     *
62
     * @return \Illuminate\Http\Response
63
     */
64
    public function render($request, Exception $exception)
65
    {
66
        return parent::render($request, $exception);
67
    }
68
69
    /**
70
     * Convert an authentication exception into an unauthenticated response.
71
     *
72
     * @param \Illuminate\Http\Request                 $request
73
     * @param \Illuminate\Auth\AuthenticationException $exception
74
     *
75
     * @return \Illuminate\Http\Response
76
     */
77
    protected function unauthenticated($request, AuthenticationException $exception)
78
    {
79
        if ($request->expectsJson()) {
80
            return response()->json(['error' => 'Unauthenticated.'], 401);
0 ignored issues
show
Bug Best Practice introduced by
The expression return response()->json(...nauthenticated.'), 401) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
81
        }
82
83
        return redirect()->guest('login');
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->guest('login') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
84
    }
85
}
86