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

Authenticate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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