Completed
Pull Request — master (#45)
by Şəhriyar
11:38
created

Authenticate   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 40
ccs 7
cts 9
cp 0.7778
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 12 3
1
<?php namespace App\Http\Middleware;
2
3
use Illuminate\Contracts\Auth\Guard;
4
use Illuminate\Http\Request;
5
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
6
7
class Authenticate
8
{
9
    /**
10
     * The Guard implementation.
11
     *
12
     * @var Guard
13
     */
14
    protected $auth;
15
16
    /**
17
     * Create a new filter instance.
18
     *
19
     * @param  Guard $auth
20
     */
21 1
    public function __construct(Guard $auth)
22
    {
23 1
        $this->auth = $auth;
24 1
    }
25
26
    /**
27
     * Handle an incoming request.
28
     *
29
     * @param  Request  $request
30
     * @param  \Closure $next
31
     *
32
     * @return mixed
33
     */
34 1
    public function handle(Request $request, \Closure $next)
35
    {
36 1
        if (app('auth.driver')->guest()) {
37 1
            if ($request->expectsJson()) {
38
                throw new UnauthorizedHttpException('Unauthorized');
39
            } else {
40 1
                return redirect()->guest(route(app('translator')->getLocale() . '.login'));
41
            }
42
        }
43
44
        return $next($request);
45
    }
46
}
47