Handler::render()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Database\Eloquent\ModelNotFoundException;
7
use Illuminate\Support\Facades\Response;
8
use Symfony\Component\HttpKernel\Exception\HttpException;
9
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
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 Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

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