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 Giuga\LaravelNovaSidebar\Http\Middleware;
4
5
use Giuga\LaravelNovaSidebar\NovaSidebar;
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 NovaSidebar;
0 ignored issues
show
Bug introduced by
The class Giuga\LaravelNovaSidebar\NovaSidebar does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
33
    }
34
}
35