Passed
Push — master ( 9aa048...898b5e )
by Mattia
04:05
created

Handler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 20
dl 0
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A report() 0 3 1
A render() 0 21 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Exceptions;
6
7
use Exception;
8
use Illuminate\Auth\Access\AuthorizationException;
9
use Illuminate\Database\Eloquent\ModelNotFoundException;
10
use Illuminate\Validation\ValidationException;
11
use Laravel\Lumen\Exceptions\Handler as ExceptionHandler;
12
use Minepic\Misc\SplashMessage;
13
use Symfony\Component\HttpKernel\Exception\HttpException;
14
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
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
        AuthorizationException::class,
25
        HttpException::class,
26
        ModelNotFoundException::class,
27
        ValidationException::class,
28
    ];
29
30
    /**
31
     * Report or log an exception.
32
     *
33
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
34
     */
35
    public function report(Exception $e)
36
    {
37
        parent::report($e);
38
    }
39
40
    /**
41
     * Render an exception into an HTTP response.
42
     *
43
     * @param \Illuminate\Http\Request $request
44
     * @param Exception                $e
45
     *
46
     * @throws Exception
47
     *
48
     * @return mixed
49
     */
50
    public function render($request, Exception $e)
51
    {
52
        if ($e instanceof NotFoundHttpException) {
53
            return response(
54
                view('public.template.header', [
55
                    'title' => 'Ooops 404! - Minepic',
56
                    'description' => 'Error content not found',
57
                    'keywords' => '404, error',
58
                    'randomMessage' => SplashMessage::get404(),
59
                ]).
60
                view('public.errors.404').
61
                view('public.template.footer'),
62
                404
63
            );
64
        }
65
66
        if ($e instanceof NotFoundHttpJsonException) {
67
            return response(['ok' => false, $e->getMessage()], 404);
0 ignored issues
show
Bug introduced by
array('ok' => false, $e->getMessage()) of type array<integer|string,false|string> is incompatible with the type string expected by parameter $content of response(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
            return response(/** @scrutinizer ignore-type */ ['ok' => false, $e->getMessage()], 404);
Loading history...
68
        }
69
70
        return parent::render($request, $e);
71
    }
72
}
73