Completed
Push — feature/manager_localization2 ( de29b5...0f36f8 )
by Xander
16:57 queued 09:59
created

Handler::report()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
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
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Handler
Loading history...
13
{
14
    /**
15
     * A list of the exception types that are not reported.
16
     *
17
     * @var array
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
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
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
40
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
41
     */
42 2
    public function report(Exception $exception)
43
    {
44 2
        parent::report($exception);
45 2
    }
46
47
    /**
48
     * Render an exception into an HTTP response.
49
     *
50
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style 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
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
53
     */
54 2
    public function render($request, Exception $exception)
55
    {
56 2
        return parent::render($request, $exception);
57
    }
58
59
    /**
60
     * Convert an authentication exception into an unauthenticated response.
61
     *
62
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 17 spaces after parameter type; 2 found
Loading history...
63
     * @param  \Illuminate\Auth\AuthenticationException  $exception
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
64
     * @return \Illuminate\Http\Response
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
65
     */
66
    protected function unauthenticated($request, AuthenticationException $exception)
67
    {
68
        if ($request->expectsJson()) {
69
            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...
70
        }
71
        if (WhichPortal::isManagerPortal()) {
72
            $loginRoute = route('manager.login');
73
        } else {
74
            $loginRoute = route('login');
75
        }
76
        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...
77
    }
78
79
    /**
80
     * OVERRIDE
81
     * Render the given HttpException.
82
     *
83
     * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
84
     * @return \Symfony\Component\HttpFoundation\Response
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
85
     */
86
    protected function renderHttpException(HttpException $e)
87
    {
88
        if (! view()->exists("errors.{$e->getStatusCode()}")) {
89
            return response()->view('errors.default', [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
90
                'exception' => $e,
91
                'goc' => Lang::get('common/goc'),
92
                'alert' => Lang::get('common/alert'),
93
                'error' => [
94
                    "title" => "Error"
95
                ]
96
            ], 500, $e->getHeaders());
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
97
        }
98
        return parent::renderHttpException($e);
99
    }
100
}
101