Privileged   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 18 6
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use App\Models\GroupModel;
6
use App\Models\ContestModel;
7
use Closure, Auth, Redirect;
8
9
class Privileged
10
{
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param  \Illuminate\Http\Request  $request
15
     * @param  \Closure  $next
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next)
19
    {
20
        if (Auth::check()) {
21
            if (isset($request->gcode)) {
22
                //group privilege
23
                $groupModel=new GroupModel();
24
                if ($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2) {
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
25
                    return $next($request);
26
                }
27
            } elseif (isset($request->cid)) {
28
                //contest privilege
29
                $contestModel=new ContestModel();
30
                if ($contestModel->judgeClearance($request->cid, Auth::user()->id)==3) {
31
                    return $next($request);
32
                }
33
            }
34
        }
35
        return Redirect::back();
36
    }
37
}
38