Completed
Push — master ( cdd4f6...ad8bd5 )
by Ryan
02:09
created

AuthorizeControlPanel   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 0
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 namespace Anomaly\UsersModule\Http\Middleware;
2
3
use Anomaly\Streams\Platform\Support\Authorizer;
4
use Closure;
5
use Illuminate\Http\Request;
6
7
/**
8
 * Class AuthorizeControlPanel
9
 *
10
 * @link          http://anomaly.is/streams-platform
11
 * @author        AnomalyLabs, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 * @package       Anomaly\Streams\Platform\Http\Middleware
14
 */
15
class AuthorizeControlPanel
16
{
17
18
    /**
19
     * The authorizer utility.
20
     *
21
     * @var Authorizer
22
     */
23
    protected $authorizer;
24
25
    /**
26
     * Create a new AuthorizeControlPanel instance.
27
     *
28
     * @param Authorizer $authorizer
29
     */
30
    public function __construct(Authorizer $authorizer)
31
    {
32
        $this->authorizer = $authorizer;
33
    }
34
35
    /**
36
     * Check the authorization of module access.
37
     *
38
     * @param  Request  $request
39
     * @param  \Closure $next
40
     * @return mixed
41
     */
42
    public function handle(Request $request, Closure $next)
43
    {
44
        if ($request->segment(1) !== 'admin') {
45
            return $next($request);
46
        }
47
48
        if (!$this->authorizer->authorize('streams::control_panel.access')) {
49
            abort(403);
50
        }
51
52
        return $next($request);
53
    }
54
}
55