Passed
Push — bugfix/manager-not-created-aft... ( fcd1af )
by Chris
10:00
created

Handler::render()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 3
cts 4
cp 0.75
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2.0625
1
<?php
2
3
namespace App\Exceptions;
4
5
use Exception;
6
use Illuminate\Auth\AuthenticationException;
7
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
8
use Symfony\Component\HttpKernel\Exception\HttpException;
9
use Facades\App\Services\WhichPortal;
10
use Illuminate\Support\Facades\Lang;
11
12
class Handler extends ExceptionHandler
13
{
14
    /**
15
     * A list of the exception types that are not reported.
16
     *
17
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \App\Exceptions\Handler::$dontReport does not specify type hint for its items.
Loading history...
18
     */
19
    protected $dontReport = [
20
        //
21
    ];
22
23
    /**
24
     * A list of the inputs that are never flashed for validation exceptions.
25
     *
26
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \App\Exceptions\Handler::$dontFlash does not specify type hint for its items.
Loading history...
27
     */
28
    protected $dontFlash = [
29
        'password',
30
        'password_confirmation',
31
        'old_password',
32
        'new_password',
33
        'new_password_confirmation',
34
    ];
35
36
    /**
37
     * Report or log an exception.
38
     *
39
     * @param  \Exception  $exception
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
40
     * @return void
41
     */
42 5
    public function report(Exception $exception)
0 ignored issues
show
introduced by
Method \App\Exceptions\Handler::report() does not have return type hint for its return value but it should be possible to add it based on @return annotation "void".
Loading history...
43
    {
44 5
        parent::report($exception);
45 5
    }
46
47
    /**
48
     * Render an exception into an HTTP response.
49
     *
50
     * @param  \Illuminate\Http\Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
51
     * @param  \Exception  $exception
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 15 spaces after parameter type; 2 found
Loading history...
52
     * @return \Illuminate\Http\Response
53
     */
54 5
    public function render($request, Exception $exception)
1 ignored issue
show
introduced by
Method \App\Exceptions\Handler::render() does not have parameter type hint for its parameter $request but it should be possible to add it based on @param annotation "\Illuminate\Http\Request".
Loading history...
introduced by
Method \App\Exceptions\Handler::render() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Illuminate\Http\Response".
Loading history...
Coding Style introduced by
Type hint "\Illuminate\Http\Request" missing for $request
Loading history...
55
    {
56 5
        if ($exception instanceof AdminException) {
57
            return $exception->render($request);
58
        }
59 5
        return parent::render($request, $exception);
60
    }
61
62
    /**
63
     * Convert an authentication exception into an unauthenticated response.
64
     *
65
     * @param  \Illuminate\Http\Request  $request
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 17 spaces after parameter type; 2 found
Loading history...
66
     * @param  \Illuminate\Auth\AuthenticationException  $exception
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
67
     * @return \Illuminate\Http\Response
68
     */
69 1
    protected function unauthenticated($request, AuthenticationException $exception)
1 ignored issue
show
introduced by
Method \App\Exceptions\Handler::unauthenticated() does not have parameter type hint for its parameter $request but it should be possible to add it based on @param annotation "\Illuminate\Http\Request".
Loading history...
introduced by
Method \App\Exceptions\Handler::unauthenticated() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Illuminate\Http\Response".
Loading history...
Coding Style introduced by
Type hint "\Illuminate\Http\Request" missing for $request
Loading history...
70
    {
71 1
        if ($request->expectsJson()) {
72
            return response()->json(['error' => 'Unauthenticated.'], 401);
1 ignored issue
show
Bug Best Practice introduced by
The expression return response()->json(...nauthenticated.'), 401) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
73
        }
74 1
        if (WhichPortal::isManagerPortal()) {
75
            $loginRoute = route('manager.login');
76
        } else {
77 1
            $loginRoute = route('login');
78
        }
79 1
        return redirect()->guest($loginRoute);
1 ignored issue
show
Bug Best Practice introduced by
The expression return redirect()->guest($loginRoute) returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
80
    }
81
82
    /**
83
     * OVERRIDE
84
     * Render the given HttpException.
85
     *
86
     * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
2 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
87
     * @return \Symfony\Component\HttpFoundation\Response
88
     */
89 3
    protected function renderHttpException(HttpException $e)
0 ignored issues
show
introduced by
Method \App\Exceptions\Handler::renderHttpException() does not have return type hint for its return value but it should be possible to add it based on @return annotation "\Symfony\Component\HttpFoundation\Response".
Loading history...
90
    {
91 3
        if (! view()->exists("errors.{$e->getStatusCode()}")) {
92 3
            return response()->view('errors.default', [
93 3
                'exception' => $e,
94 3
                'goc' => Lang::get('common/goc'),
95 3
                'alert' => Lang::get('common/alert'),
96
                'error' => [
97
                    "title" => "Error"
98
                ]
99 3
            ], $e->getStatusCode(), $e->getHeaders());
100
        }
101
        return parent::renderHttpException($e);
102
    }
103
}
104