AuthorizeControlPanel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 7.5 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 3
loc 40
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 3 12 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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