Handler::report()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Database\Eloquent\ModelNotFoundException;
7
use Symfony\Component\HttpKernel\Exception\HttpException;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
10
use Illuminate\Support\Facades\Response;
11
12
class Handler extends ExceptionHandler
13
{
14
    /**
15
     * A list of the exception types that should not be reported.
16
     *
17
     * @var array
18
     */
19
    protected $dontReport = [
20
        HttpException::class,
21
        ModelNotFoundException::class,
22
    ];
23
24
    /**
25
     * Report or log an exception.
26
     *
27
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
28
     *
29
     * @param  \Exception  $e
30
     * @return void
31
     */
32
    public function report(Exception $e)
33
    {
34
        return parent::report($e);
35
    }
36
37
    /**
38
     * Render an exception into an HTTP response.
39
     *
40
     * @param  \Illuminate\Http\Request  $request
41
     * @param  \Exception  $e
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function render($request, Exception $e)
45
    {
46
        if ($e instanceof ModelNotFoundException) {
47
            $e = new NotFoundHttpException($e->getMessage(), $e);
0 ignored issues
show
Unused Code introduced by
$e is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
48
            return Response::json(['error' => ['message' => 'Resource not found']], 404);
49
        }
50
51
        return parent::render($request, $e);
52
    }
53
}
54