Passed
Push — main ( 021ea8...bae248 )
by Yaroslav
02:48
created

Authorize   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
c 1
b 0
f 0
dl 0
loc 25
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 2
A matchesTool() 0 3 1
1
<?php
2
3
namespace NovaNavigaAdPreview\Http\Middleware;
4
5
use Laravel\Nova\Nova;
6
use NovaNavigaAdPreview\NovaNavigaAdPreview;
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 2
    public function handle($request, $next)
18
    {
19 2
        $tool = collect(Nova::registeredTools())->first([$this, 'matchesTool']);
0 ignored issues
show
Bug introduced by
Laravel\Nova\Nova::registeredTools() of type array<integer,Laravel\Nova\Tool> is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

19
        $tool = collect(/** @scrutinizer ignore-type */ Nova::registeredTools())->first([$this, 'matchesTool']);
Loading history...
20
21 2
        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 2
    public function matchesTool($tool)
31
    {
32 2
        return $tool instanceof NovaNavigaAdPreview;
33
    }
34
}
35