Passed
Pull Request — 2.x (#586)
by Bekzat
05:24 queued 25s
created

Impersonate::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace A17\Twill\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Factory as AuthFactory;
7
8
class Impersonate
9
{
10
    /**
11
     * @var AuthFactory
12
     */
13
    protected $authFactory;
14
15 49
    public function __construct(AuthFactory $authFactory)
16
    {
17 49
        $this->authFactory = $authFactory;
18 49
    }
19
20
    /**
21
     * Handles an incoming request.
22
     *
23
     * @param \Illuminate\Http\Request $request
24
     * @param Closure $next
25
     * @return mixed
26
     */
27 48
    public function handle($request, Closure $next)
28
    {
29 48
        if ($request->session()->has('impersonate')) {
30
            $this->authFactory->guard('twill_users')->onceUsingId($request->session()->get('impersonate'));
31
        }
32
33 48
        return $next($request);
34
    }
35
}
36