AuthorizeControlPanel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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://pyrocms.com/
11
 * @author        PyroCMS, Inc. <[email protected]>
12
 * @author        Ryan Thompson <[email protected]>
13
 */
14
class AuthorizeControlPanel
15
{
16
17
    /**
18
     * The authorizer utility.
19
     *
20
     * @var Authorizer
21
     */
22
    protected $authorizer;
23
24
    /**
25
     * Create a new AuthorizeControlPanel instance.
26
     *
27
     * @param Authorizer $authorizer
28
     */
29
    public function __construct(Authorizer $authorizer)
30
    {
31
        $this->authorizer = $authorizer;
32
    }
33
34
    /**
35
     * Check the authorization of module access.
36
     *
37
     * @param  Request  $request
38
     * @param  \Closure $next
39
     * @return mixed
40
     */
41
    public function handle(Request $request, Closure $next)
42
    {
43 View Code Duplication
        if ($request->segment(1) !== 'admin' || in_array($request->path(), ['admin/login', 'admin/logout'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
            return $next($request);
45
        }
46
47
        if (!$this->authorizer->authorize('streams::control_panel.access')) {
48
            abort(403);
49
        }
50
51
        return $next($request);
52
    }
53
}
54