Authenticate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 36
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 Gitamin.
5
 *
6
 * Copyright (C) 2015-2016 The Gitamin Team
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 Gitamin\Http\Middleware;
13
14
use Closure;
15
use Illuminate\Contracts\Auth\Guard;
16
use Symfony\Component\HttpKernel\Exception\HttpException;
17
18
class Authenticate
19
{
20
    /**
21
     * The authentication guard instance.
22
     *
23
     * @var \Illuminate\Contracts\Auth\Guard
24
     */
25
    protected $auth;
26
27
    /**
28
     * Create a new authenticate middleware instance.
29
     *
30
     * @param \Illuminate\Contracts\Auth\Guard $auth
31
     */
32
    public function __construct(Guard $auth)
33
    {
34
        $this->auth = $auth;
35
    }
36
37
    /**
38
     * Handle an incoming request.
39
     *
40
     * @param \Illuminate\Http\Request $request
41
     * @param \Closure                 $next
42
     *
43
     * @return mixed
44
     */
45
    public function handle($request, Closure $next)
46
    {
47
        if ($this->auth->guest()) {
48
            throw new HttpException(401);
49
        }
50
51
        return $next($request);
52
    }
53
}
54