Completed
Push — develop ( 1c3d8e...dc7d05 )
by Mohamed
07:44
created

RedirectIfAuthenticated   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 36
c 0
b 0
f 0
ccs 0
cts 11
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 8 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Middleware;
13
14
use Closure;
15
use Illuminate\Contracts\Auth\Guard;
16
use Illuminate\Http\RedirectResponse;
17
use Illuminate\Http\Request;
18
19
/**
20
 * RedirectIfAuthenticated is a Middleware class to redirect logged user to dashboard instead of login page.
21
 *
22
 * @author Mohamed Alsharaf <[email protected]>
23
 */
24
class RedirectIfAuthenticated
25
{
26
    /**
27
     * The Guard implementation.
28
     *
29
     * @var Guard
30
     */
31
    protected $auth;
32
33
    /**
34
     * Create a new filter instance.
35
     *
36
     * @param Guard $auth
37
     */
38
    public function __construct(Guard $auth)
39
    {
40
        $this->auth = $auth;
41
    }
42
43
    /**
44
     * Handle an incoming request.
45
     *
46
     * @param Request  $request
47
     * @param \Closure $next
48
     *
49
     * @return mixed
50
     */
51
    public function handle(Request $request, Closure $next)
52
    {
53
        if ($this->auth->check()) {
54
            return new RedirectResponse(url('/home'));
55
        }
56
57
        return $next($request);
58
    }
59
}
60