Handler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 66
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 4 1
A render() 0 10 3
A unauthenticated() 0 8 2
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Exceptions;
9
10
use Exception;
11
use Illuminate\Auth\AuthenticationException;
12
use GrahamCampbell\Exceptions\ExceptionHandler;
13
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
15
16
class Handler extends ExceptionHandler
17
{
18
    /**
19
     * A list of the exception types that should not be reported.
20
     *
21
     * @var array
22
     */
23
    protected $dontReport = [
24
        \Illuminate\Auth\AuthenticationException::class,
25
        \Illuminate\Auth\Access\AuthorizationException::class,
26
        \Symfony\Component\HttpKernel\Exception\HttpException::class,
27
        \Illuminate\Database\Eloquent\ModelNotFoundException::class,
28
        \Illuminate\Session\TokenMismatchException::class,
29
        \Illuminate\Validation\ValidationException::class,
30
    ];
31
32
    /**
33
     * Report or log an exception.
34
     *
35
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
36
     *
37
     * @param \Exception $exception
38
     *
39
     * @return void
40
     */
41
    public function report(Exception $exception)
42
    {
43
        parent::report($exception);
44
    }
45
46
    /**
47
     * Render an exception into an HTTP response.
48
     *
49
     * @param \Illuminate\Http\Request $request
50
     * @param \Exception               $exception
51
     *
52
     * @return \Illuminate\Http\Response
53
     */
54
    public function render($request, Exception $exception)
55
    {
56
        if ($exception instanceof NotFoundHttpException) {
57
            return response()->view('errors.404', [], 404);
58
        } elseif ($exception instanceof AccessDeniedHttpException) {
59
            return response()->view('errors.403', [], 403);
60
        }
61
62
        return parent::render($request, $exception);
63
    }
64
65
    /**
66
     * Convert an authentication exception into an unauthenticated response.
67
     *
68
     * @param \Illuminate\Http\Request                 $request
69
     * @param \Illuminate\Auth\AuthenticationException $exception
70
     *
71
     * @return \Illuminate\Http\Response
0 ignored issues
show
Documentation introduced by
Should the return type not be \Illuminate\Http\JsonRes...e\Http\RedirectResponse?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
72
     */
73
    protected function unauthenticated($request, AuthenticationException $exception)
0 ignored issues
show
Unused Code introduced by
The parameter $exception is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
    {
75
        if ($request->expectsJson()) {
76
            return response()->json(['error' => 'Unauthenticated.'], 401);
77
        }
78
79
        return redirect()->guest('login');
80
    }
81
}
82