ForceUpdate   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 2 Features 0
Metric Value
eloc 9
c 2
b 2
f 0
dl 0
loc 28
rs 10
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 6
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Request;
7
8
class ForceUpdate
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @return mixed
15
     */
16
    public function handle($request, Closure $next)
17
    {
18
        if (Request::isMethod('post')) {
19
            return $next($request);
20
        }
21
22
        // if the current user has a forceupdate field set, we check that they can only access this route or a lower forceupdate step
23
24
        if (backpack_user() != null) {
25
            if (backpack_user()->isStudent()) {
0 ignored issues
show
Bug introduced by
The method isStudent() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

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

25
            if (backpack_user()->/** @scrutinizer ignore-call */ isStudent()) {
Loading history...
26
                if (backpack_user()->student->force_update) {
0 ignored issues
show
Bug introduced by
Accessing student on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
27
                    // if the user wants to go further than authorized, redirect them to the current step
28
                    if ($request->path() != 'edit/'.backpack_user()->student->force_update) {
29
                        return redirect(url('edit/'.backpack_user()->student->force_update));
30
                    }
31
                }
32
            }
33
        }
34
35
        return $next($request);
36
    }
37
}
38