Passed
Pull Request — master (#2)
by ANTHONIUS
05:01
created

Authenticate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 2
A __construct() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the EOffice project.
5
 *
6
 * (c) Anthonius Munthi <https://itstoni.com>
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
declare(strict_types=1);
13
14
namespace EOffice\Auth\Middleware;
15
16
use Closure;
17
use Illuminate\Contracts\Auth\Factory as Auth;
18
use Illuminate\Http\Request;
19
use function response;
20
21
class Authenticate
22
{
23
    /**
24
     * The authentication guard factory instance.
25
     *
26
     * @var Auth
27
     */
28
    protected $auth;
29
30
    /**
31
     * Create a new middleware instance.
32
     *
33
     * @param Auth $auth
34
     *
35
     * @return void
36
     */
37
    public function __construct(Auth $auth)
38
    {
39
        $this->auth = $auth;
40
    }
41
42
    /**
43
     * Handle an incoming request.
44
     *
45
     * @param Request $request
46
     * @param \Closure                 $next
47
     * @param string|null              $guard
48
     *
49
     * @return mixed
50
     */
51
    public function handle($request, Closure $next, $guard = null)
52
    {
53
        if ($this->auth->guard($guard)->guest()) {
54
            return response('Unauthorized.', 401);
55
        }
56
57
        return $next($request);
58
    }
59
}
60