Completed
Push — develop ( 10b573...34b970 )
by Abdelrahman
09:38
created

Abilities   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Fort\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Http\Request;
9
use Rinvex\Fort\Models\User;
10
use Illuminate\Support\Facades\Gate;
11
use Illuminate\Database\Eloquent\Model;
12
13
class Abilities
14
{
15
    /**
16
     * Handle an incoming request.
17
     *
18
     * @param \Illuminate\Http\Request $request
19
     * @param \Closure                 $next
20
     *
21
     * @return mixed
22
     */
23
    public function handle(Request $request, Closure $next)
24
    {
25
        // Bypass authorization check if superadmin
26
        Gate::before(function (User $user) {
27
            return $user->isSuperadmin() ?: null;
28
        });
29
30
        // Define abilities and policies
31
        app('rinvex.fort.ability')->all()->map(function ($ability) {
32
            Gate::define($ability->slug, $ability->policy ?: function (User $user, Model $resource = null) use ($ability) {
0 ignored issues
show
Unused Code introduced by
The parameter $resource is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 123 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
33
                return $user->allAbilities->pluck('slug')->contains($ability->slug);
34
            });
35
        });
36
37
        return $next($request);
38
    }
39
}
40