Authorize   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 6 2
A matchesTool() 0 4 1
1
<?php
2
3
namespace BBSLab\NovaPermission\Http\Middleware;
4
5
use BBSLab\NovaPermission\PermissionBuilder;
6
use Laravel\Nova\Nova;
7
8
class Authorize
9
{
10
    /**
11
     * Handle the incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return \Illuminate\Http\Response
16
     */
17
    public function handle($request, $next)
18
    {
19
        $tool = collect(Nova::registeredTools())->first([$this, 'matchesTool']);
20
21
        return optional($tool)->authorize($request) ? $next($request) : abort(403);
22
    }
23
24
    /**
25
     * Determine whether this tool belongs to the package.
26
     *
27
     * @param  \Laravel\Nova\Tool  $tool
28
     * @return bool
29
     */
30
    public function matchesTool($tool)
31
    {
32
        return $tool instanceof PermissionBuilder;
33
    }
34
}
35