RedirectIfAuthenticated::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.7462

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 7
cp 0.4286
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2.7462
1
<?php
2
3
namespace PiFinder\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
use Illuminate\Http\RedirectResponse;
8
9
class RedirectIfAuthenticated
10
{
11
    /**
12
     * The Guard implementation.
13
     *
14
     * @var Guard
15
     */
16
    protected $auth;
17
18
    /**
19
     * Create a new filter instance.
20
     *
21
     * @param Guard $auth
22
     */
23 1
    public function __construct(Guard $auth)
24
    {
25 1
        $this->auth = $auth;
26 1
    }
27
28
    /**
29
     * Handle an incoming request.
30
     *
31
     * @param \Illuminate\Http\Request $request
32
     * @param \Closure                 $next
33
     *
34
     * @return mixed
35
     */
36 1
    public function handle($request, Closure $next)
37
    {
38 1
        if ($this->auth->check()) {
39
            return new RedirectResponse(url('/home'));
0 ignored issues
show
Bug introduced by
It seems like url('/home') targeting url() can also be of type object<Illuminate\Contracts\Routing\UrlGenerator>; however, Symfony\Component\HttpFo...Response::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
40
        }
41
42 1
        return $next($request);
43
    }
44
}
45