Completed
Pull Request — dev (#312)
by Tristan
09:36 queued 03:25
created

Handler::unauthenticated()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 12
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 Facades\App\Services\WhichPortal;
0 ignored issues
show
Bug introduced by
The type Facades\App\Services\WhichPortal was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class Handler extends ExceptionHandler
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class Handler
Loading history...
11
{
12
    /**
13
     * A list of the exception types that are not reported.
14
     *
15
     * @var array
16
     */
17
    protected $dontReport = [
18
        //
19
    ];
20
21
    /**
22
     * A list of the inputs that are never flashed for validation exceptions.
23
     *
24
     * @var array
25
     */
26
    protected $dontFlash = [
27
        'password',
28
        'password_confirmation',
29
    ];
30
31
    /**
32
     * Report or log an exception.
33
     *
34
     * @param  \Exception  $exception
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
35
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
36
     */
37 2
    public function report(Exception $exception)
38
    {
39 2
        parent::report($exception);
40 2
    }
41
42
    /**
43
     * Render an exception into an HTTP response.
44
     *
45
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
46
     * @param  \Exception  $exception
0 ignored issues
show
Coding Style introduced by
Expected 15 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
47
     * @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...
48
     */
49 2
    public function render($request, Exception $exception)
50
    {
51 2
        return parent::render($request, $exception);
52
    }
53
54
    /**
55
     * Convert an authentication exception into an unauthenticated response.
56
     *
57
     * @param  \Illuminate\Http\Request  $request
0 ignored issues
show
Coding Style introduced by
Expected 17 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
58
     * @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...
59
     * @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...
60
     */
61
    protected function unauthenticated($request, AuthenticationException $exception)
62
    {
63
        if ($request->expectsJson()) {
64
            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...
65
        }
66
        if (WhichPortal::isManagerPortal()) {
67
            $loginRoute = route('manager.login');
68
        } else {
69
            $loginRoute = route('login');
70
        }
71
        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...
72
    }
73
}
74