Privileged::handle()   A
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 6
nop 2
dl 0
loc 18
rs 9.2222
c 0
b 0
f 0
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