UserMiddleware::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 2
crap 2
1
<?php
2
3
/**
4
 * @package     Dashboard
5
 * @author      Ian Olson <[email protected]>
6
 * @license     MIT
7
 * @copyright   2015, Laraflock
8
 * @link        https://github.com/laraflock
9
 */
10
11
namespace Laraflock\Dashboard\Middleware;
12
13
use Closure;
14
use Illuminate\Http\Request;
15
use Laracasts\Flash\Flash;
16
use Laraflock\Dashboard\Repositories\Auth\AuthRepositoryInterface as Auth;
17
18
class UserMiddleware
19
{
20
    /**
21
     * Auth interface.
22
     *
23
     * @var Auth
24
     */
25
    protected $auth;
26
27
    /**
28
     * The constructor.
29
     *
30
     * @param Auth $auth
31
     */
32 2
    public function __construct(Auth $auth)
33
    {
34 2
        $this->auth = $auth;
35 2
    }
36
37
    /**
38
     * Check if a user is logged in.
39
     *
40
     * @param Request $request
41
     * @param Closure $next
42
     *
43
     * @return \Illuminate\Http\RedirectResponse
44
     */
45 2
    public function handle(Request $request, Closure $next)
46
    {
47 2
        if (!$this->auth->check()) {
48 1
            Flash::error(trans('dashboard::dashboard.flash.access_denied'));
49
50 1
            return redirect()->route('auth.login');
51
        }
52
53 1
        return $next($request);
54
    }
55
}