Completed
Pull Request — master (#59)
by
unknown
01:25
created

ProtectAuthenticateImpersonation   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 11 2
1
<?php
2
3
namespace Lab404\Impersonate\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Redirect;
7
use Illuminate\Contracts\Auth\Factory as Auth;
8
9
class ProtectAuthenticateImpersonation
10
{
11
    /**
12
     * The authentication factory instance.
13
     *
14
     * @var \Illuminate\Contracts\Auth\Factory
15
     */
16
    protected $auth;
17
18
    public function __construct(Auth $auth)
19
    {
20
        $this->auth = $auth;
21
    }
22
23
    /**
24
     * Handle an incoming request.
25
     *
26
     * @param   \Illuminate\Http\Request  $request
27
     * @param   \Closure  $next
28
     * @return  mixed
29
     */
30
    public function handle($request, Closure $next)
31
    {
32
        $guard = session(config('laravel-impersonate.session_guard'), config('auth.defaults.guard'));
33
34
        if(!$this->auth->guard($guard)->check())
35
        {
36
            return Redirect::back();
37
        }
38
39
        return $next($request);
40
    }
41
}