Authenticate::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 13
cp 0
rs 10
cc 3
nc 3
nop 2
crap 12
1
<?php namespace Distilleries\Expendable\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Contracts\Auth\Guard;
5
use Illuminate\Contracts\Config\Repository;
6
7
class Authenticate {
8
9
    /**
10
     * The Guard implementation.
11
     *
12
     * @var Guard
13
     */
14
    protected $auth;
15
    protected $config;
16
17
    /**
18
     * Create a new filter instance.
19
     *
20
     * @param  Guard $auth
21
     */
22
    public function __construct(Guard $auth, Repository $config)
23
    {
24
        $this->auth   = $auth;
25
        $this->config = $config;
26
    }
27
28
    /**
29
     * Handle an incoming request.
30
     *
31
     * @param  \Illuminate\Http\Request $request
32
     * @param  \Closure $next
33
     * @return mixed
34
     */
35
    public function handle($request, Closure $next)
36
    {
37
        if ($this->auth->guest())
38
        {
39
            if ($request->ajax())
40
            {
41
                return response('Unauthorized.', 401);
42
            } else
43
            {
44
                return redirect()->guest($this->config->get('expendable.login_uri'));
45
            }
46
        }
47
48
        return $next($request);
49
    }
50
}