Handler::report()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Colligator\Exceptions;
4
5
use Exception;
6
use Illuminate\Auth\AuthenticationException;
7
use Illuminate\Database\Eloquent\ModelNotFoundException;
8
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
9
use Illuminate\Validation\ValidationException;
10
use Illuminate\Auth\Access\AuthorizationException;
11
use Symfony\Component\HttpKernel\Exception\HttpException;
12
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13
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
        AuthorizationException::class,
24
        HttpException::class,
25
        ModelNotFoundException::class,
26
        ValidationException::class,
27
    ];
28
29
    /**
30
     * A list of the inputs that are never flashed for validation exceptions.
31
     *
32
     * @var array
33
     */
34
    protected $dontFlash = [
35
        'password',
36
        'password_confirmation',
37
    ];
38
39
    /**
40
     * Report or log an exception.
41
     *
42
     * @param  \Exception  $exception
43
     * @return void
44
     */
45
    public function report(Exception $exception)
46
    {
47
        parent::report($exception);
48
    }
49
50
    /**
51
     * Render an exception into an HTTP response.
52
     *
53
     * @param \Illuminate\Http\Request $request
54
     * @param \Exception               $e
55
     *
56
     * @return \Symfony\Component\HttpFoundation\Response
57
     */
58
    public function render($request, Exception $e)
59
    {
60
        if ($e instanceof NotFoundHttpException) {
61
            return \Response::make([
0 ignored issues
show
Documentation introduced by
array('error' => 'not_fo...the URL you submitted') is of type array<string,string,{"er...ror_message":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
                'error' => 'not_found',
63
                'error_message' => 'Please check the URL you submitted'
64
            ], 404);
65
        }
66
        if ($e instanceof ModelNotFoundException) {
67
            abort(404);
68
        }
69
        if (method_exists($e, 'render')) {
70
            return $e->render();
71
        }
72
73
        return parent::render($request, $e);
74
    }
75
76
    /**
77
     * Convert an authentication exception into an unauthenticated response.
78
     *
79
     * @param  \Illuminate\Http\Request  $request
80
     * @param  \Illuminate\Auth\AuthenticationException  $exception
81
     * @return \Illuminate\Http\Response
82
     */
83
    protected function unauthenticated($request, AuthenticationException $exception)
84
    {
85
        if ($request->expectsJson()) {
86
            return response()->json(['error' => 'Unauthenticated.'], 401);
87
        }
88
89
        return redirect()->guest('login');
90
    }
91
}
92