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

RoleMiddleware::handle()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 16
Code Lines 9

Duplication

Lines 16
Ratio 100 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 9
c 1
b 1
f 0
nc 8
nop 3
dl 16
loc 16
rs 9.2
1
<?php
2
3
namespace Spatie\Permission\Middlewares;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8 View Code Duplication
class RoleMiddleware
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, $role)
11
    {
12
        if (Auth::guest()) {
13
            abort(403);
14
        }
15
16
        $role = is_array($role)
17
            ? $role
18
            : explode('|', $role);
19
20
        if (! Auth::user()->hasAnyRole($role)) {
0 ignored issues
show
Bug introduced by
The method hasAnyRole() 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