Completed
Push — master ( 40b048...39e269 )
by Freek
01:56
created

PermissionMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 19
loc 19
rs 10
wmc 4
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 16 16 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
namespace Spatie\Permission\Middlewares;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8 View Code Duplication
class PermissionMiddleware
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...
9
{
10
    public function handle($request, Closure $next, $permission)
11
    {
12
        if (Auth::guest()) {
13
            abort(403);
14
        }
15
16
        $permission = is_array($permission)
17
            ? $permission
18
            : explode('|', $permission);
19
20
        if (! Auth::user()->hasAnyPermission(...$permission)) {
0 ignored issues
show
Bug introduced by
The method hasAnyPermission() does not seem to exist on object<Illuminate\Contracts\Auth\Authenticatable>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
            abort(403);
22
        }
23
24
        return $next($request);
25
    }
26
}
27