Role   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 42
loc 42
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handle() 13 13 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
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Auth\Middleware;
12
13
use Closure;
14
use Longman\Platfourm\Contracts\Auth\AuthUserService as AuthUserServiceContract;
15
16 View Code Duplication
class Role
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
17
{
18
    /**
19
     * The Guard implementation.
20
     *
21
     * @var Guard
22
     */
23
    protected $authService;
24
25
    /**
26
     * Create a new filter instance.
27
     *
28
     * @param  Guard $auth
0 ignored issues
show
Bug introduced by
There is no parameter named $auth. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
29
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
30
     */
31
    public function __construct(AuthUserServiceContract $authService)
32
    {
33
        $this->authService = $authService;
0 ignored issues
show
Documentation Bug introduced by
It seems like $authService of type object<Longman\Platfourm...s\Auth\AuthUserService> is incompatible with the declared type object<Longman\Platfourm\Auth\Middleware\Guard> of property $authService.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
34
    }
35
36
    /**
37
     * Handle an incoming request.
38
     *
39
     * @param  \Illuminate\Http\Request $request
40
     * @param  Closure                  $next
41
     * @param                           $roles
42
     * @return mixed
43
     */
44
    public function handle($request, Closure $next, $roles)
45
    {
46
47
        if ($this->authService->guest() || !$request->user()->hasRole(explode('|', $roles))) {
48
            if ($request->wantsJson()) {
49
                return response('Forbidden.', 403);
50
            } else {
51
                abort(403);
52
            }
53
        }
54
55
        return $next($request);
56
    }
57
}
58