Scope   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 5
dl 0
loc 22
rs 10
c 1
b 0
f 1
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 3
1
<?php
2
/**
3
 * This file handle scope middleware.
4
 *
5
 * @link       https://github.com/maab16
6
 * @since      1.0.0
7
 */
8
9
namespace WPB\App\Http\Middleware;
10
11
use Closure;
12
use Illuminate\Http\Request;
13
14
/**
15
 * The scope middleware class.
16
 *
17
 * @since      1.0.0
18
 *
19
 * @author     Md Abu Ahsan basir <[email protected]>
20
 */
21
class Scope
22
{
23
    /**
24
     * Handle an incoming request.
25
     *
26
     * @param \Illuminate\Http\Request $request   The app http request.
27
     * @param \Closure                 $next      The next closure.
28
     * @param array                    ...$scopes The requested guards.
29
     *
30
     * @throws \Exception Throw the exception.
31
     *
32
     * @return mixed
33
     */
34
    public function handle(Request $request, Closure $next, ...$scopes)
35
    {
36
        foreach ($scopes as $scope) {
37
            if (!in_array($scope, $request->scopes)) {
38
                wp_send_json(['msg' => "You don't have enough permission"], 400);
0 ignored issues
show
Bug introduced by
The function wp_send_json was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

38
                /** @scrutinizer ignore-call */ 
39
                wp_send_json(['msg' => "You don't have enough permission"], 400);
Loading history...
39
            }
40
        }
41
42
        return $next($request);
43
    }
44
}
45