Authorize::matchesTool()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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