Completed
Push — master ( 43dba6...416142 )
by Mahmoud
09:25 queued 05:38
created

Authenticate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 12 3
1
<?php
2
3
namespace App\Port\Middleware\Http;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
use Illuminate\Http\Request;
8
9
/**
10
 * Class Authenticate
11
 *
12
 * @author  Mahmoud Zalt  <[email protected]>
13
 */
14
class Authenticate
15
{
16
    /**
17
     * The Guard implementation.
18
     *
19
     * @var Guard
20
     */
21
    protected $auth;
22
23
    /**
24
     * Create a new middleware instance.
25
     *
26
     * @param  Guard  $auth
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29
    public function __construct(Guard $auth)
30
    {
31
        $this->auth = $auth;
32
    }
33
34
    /**
35
     * Handle an incoming request.
36
     *
37
     * @param  \Illuminate\Http\Request  $request
38
     * @param  \Closure  $next
39
     * @return mixed
40
     */
41
    public function handle(Request $request, Closure $next)
42
    {
43
        if ($this->auth->guest()) {
44
            if ($request->ajax()) {
45
                return response('Unauthorized.', 401);
46
            } else {
47
                return redirect()->guest('auth/login');
48
            }
49
        }
50
51
        return $next($request);
52
    }
53
}
54