Completed
Push — develop ( f06541...810a8c )
by Mohamed
11:09 queued 05:53
created

Authenticate::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 3
Bugs 2 Features 0
Metric Value
c 3
b 2
f 0
dl 0
loc 12
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3.0261
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\Request;
17
18
/**
19
 * Authenticate is a Middleware class to for checking if current user is logged in.
20
 *
21
 * @author Mohamed Alsharaf <[email protected]>
22
 */
23
class Authenticate
24
{
25
    /**
26
     * The Guard implementation.
27
     *
28
     * @var Guard
29
     */
30
    protected $auth;
31
32
    /**
33
     * Create a new filter instance.
34
     *
35
     * @param Guard $auth
36
     */
37 54
    public function __construct(Guard $auth)
38
    {
39 54
        $this->auth = $auth;
40 54
    }
41
42
    /**
43
     * Handle an incoming request.
44
     *
45
     * @param Request  $request
46
     * @param \Closure $next
47
     *
48
     * @return mixed
49
     */
50 54
    public function handle(Request $request, Closure $next)
51
    {
52 54
        if ($this->auth->guest()) {
53 2
            if ($request->ajax()) {
54 1
                abort(401);
55
            }
56
57 1
            return redirect()->guest('/');
58
        }
59
60 52
        return $next($request);
61
    }
62
}
63