Handler   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 6
Bugs 1 Features 1
Metric Value
wmc 8
c 6
b 1
f 1
lcom 1
cbo 6
dl 0
loc 75
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 4 1
B render() 0 23 5
A renderExceptionWithWhoops() 0 11 2
1
<?php namespace App\Exceptions;
2
3
use Exception;
4
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
5
use Illuminate\Http\Response;
6
use Symfony\Component\HttpKernel\Exception\HttpException;
7
use Whoops\Handler\PrettyPageHandler;
8
use Whoops\Run as RunWhoops;
9
10
class Handler extends ExceptionHandler
11
{
12
13
    /**
14
     * A list of the exception types that should not be reported.
15
     *
16
     * @var array
17
     */
18
    protected $dontReport = [
19
        'Symfony\Component\HttpKernel\Exception\HttpException'
20
    ];
21
22
    /**
23
     * Report or log an exception.
24
     *
25
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
26
     *
27
     * @param  \Exception $e
28
     * @return void
29
     */
30
    public function report(Exception $e)
31
    {
32
        return parent::report($e);
33
    }
34
35
    /**
36
     * Render an exception into an HTTP response.
37
     *
38
     * @param  \Illuminate\Http\Request $request
39
     * @param  \Exception $e
40
     * @return \Illuminate\Http\Response
41
     */
42
    public function render($request, Exception $e)
43
    {
44
        if ($this->isHttpException($e)) {
45
            return $this->renderHttpException($e);
0 ignored issues
show
Compatibility introduced by
$e of type object<Exception> is not a sub-type of object<Symfony\Component...xception\HttpException>. It seems like you assume a child class of the class Exception to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
46
        }
47
48
        if (config('app.debug')) {
49
            if ($request->isXmlHttpRequest()) {
50
                return response(['message' => $e->getMessage(),
0 ignored issues
show
Documentation introduced by
array('message' => $e->g...line' => $e->getLine()) is of type array<string,*,{"message...ing","line":"integer"}>, 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...
51
                    'code' => $e->getCode(),
52
                    'file' => $e->getFile(),
53
                    'line' => $e->getLine()], 500);
54
            }
55
56
            return $this->renderExceptionWithWhoops($e);
57
        }
58
59
        if ($e instanceof RepositoryException) {
60
            return $e->jsonResponse();
61
        }
62
63
        return parent::render($request, $e);
64
    }
65
66
    /**
67
     * Render an exception using Whoops.
68
     *
69
     * @param  \Exception $e
70
     * @return \Illuminate\Http\Response
71
     */
72
    protected function renderExceptionWithWhoops(Exception $e)
73
    {
74
        $whoops = new RunWhoops();
75
        $whoops->pushHandler(new PrettyPageHandler());
0 ignored issues
show
Documentation introduced by
new \Whoops\Handler\PrettyPageHandler() is of type object<Whoops\Handler\PrettyPageHandler>, but the function expects a callable.

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...
76
77
        if ($e instanceof HttpException) {
78
            return new Response($whoops->handleException($e), $e->getStatusCode(), $e->getHeaders());
79
        }
80
81
        return new Response($whoops->handleException($e));
82
    }
83
84
}
85