GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c31bff...117582 )
by Caspar
10:25
created

Handler   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 14
dl 0
loc 105
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sendEmail() 0 10 2
A render() 0 19 6
A report() 0 13 4
A unauthenticated() 0 7 2
1
<?php
2
3
namespace App\Exceptions;
4
5
use App\Mail\ExceptionOccured;
6
use Exception;
7
use Illuminate\Auth\AuthenticationException;
8
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
9
use Illuminate\Support\Facades\Log;
10
use Illuminate\Support\Facades\Mail;
11
use Response;
12
use Symfony\Component\Debug\Exception\FlattenException;
13
use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler;
14
15
class Handler extends ExceptionHandler
16
{
17
    /**
18
     * A list of the exception types that should not be reported.
19
     *
20
     * @var array
21
     */
22
    protected $dontReport = [
23
        \Illuminate\Auth\AuthenticationException::class,
24
        \Illuminate\Auth\Access\AuthorizationException::class,
25
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
26
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
27
        \Illuminate\Session\TokenMismatchException::class,
28
        \Illuminate\Validation\ValidationException::class,
29
    ];
30
31
    /**
32
     * Report or log an exception.
33
     *
34
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
35
     *
36
     * @param \Exception $exception
37
     *
38
     * @throws Exception
39
     *
40
     * @return void
41
     */
42
    public function report(Exception $exception)
43
    {
44
        $enableEmailExceptions = config('exceptions.emailExceptionEnabled');
45
46
        if ($enableEmailExceptions === '') {
47
            $enableEmailExceptions = config('exceptions.emailExceptionEnabledDefault');
48
        }
49
50
        if ($enableEmailExceptions && $this->shouldReport($exception)) {
51
            $this->sendEmail($exception);
52
        }
53
54
        parent::report($exception);
55
    }
56
57
    /**
58
     * Render an exception into an HTTP response.
59
     *
60
     * @param \Illuminate\Http\Request $request
61
     * @param \Exception               $exception
62
     *
63
     * @return \Illuminate\Http\Response
64
     */
65
    public function render($request, Exception $exception)
66
    {
67
        $userLevelCheck = $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\RoleDeniedException ||
68
            $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\RoleDeniedException ||
69
            $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\PermissionDeniedException ||
70
            $exception instanceof \jeremykenedy\LaravelRoles\Exceptions\LevelDeniedException;
71
72
        if ($userLevelCheck) {
73
            if ($request->expectsJson()) {
74
                return Response::json([
0 ignored issues
show
Bug Best Practice introduced by
The expression return Response::json(ar... 'Unauthorized.'), 403) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
75
                    'error'   => 403,
76
                    'message' => 'Unauthorized.',
77
                ], 403);
78
            }
79
80
            abort(403);
81
        }
82
83
        return parent::render($request, $exception);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::render($request, $exception) also could return the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
84
    }
85
86
    /**
87
     * Convert an authentication exception into an unauthenticated response.
88
     *
89
     * @param \Illuminate\Http\Request                 $request
90
     * @param \Illuminate\Auth\AuthenticationException $exception
91
     *
92
     * @return \Illuminate\Http\Response
93
     */
94
    protected function unauthenticated($request, AuthenticationException $exception)
95
    {
96
        if ($request->expectsJson()) {
97
            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...
98
        }
99
100
        return redirect()->guest(route('login'));
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->guest(route('login')) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
101
    }
102
103
    /**
104
     * Sends an email upon exception.
105
     *
106
     * @param \Exception $exception
107
     *
108
     * @return void
109
     */
110
    public function sendEmail(Exception $exception)
111
    {
112
        try {
113
            $e = FlattenException::create($exception);
114
            $handler = new SymfonyExceptionHandler();
115
            $html = $handler->getHtml($e);
116
117
            Mail::send(new ExceptionOccured($html));
118
        } catch (Exception $exception) {
119
            Log::error($exception);
120
        }
121
    }
122
}
123