GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 492a38...52bad7 )
by Anthony
11:04 queued 11s
created

CheckForReadOnlyMode::handle()   C

Complexity

Conditions 12
Paths 4

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 16
cts 16
cp 1
rs 6.9666
c 0
b 0
f 0
cc 12
nc 4
nop 2
crap 12

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Rappasoft\Lockout\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Response;
7
8
/**
9
 * Class CheckForReadOnlyMode.
10
 */
11
class CheckForReadOnlyMode
12
{
13
    /**
14
     * @param $request
15
     * @param  Closure  $next
16
     *
17
     * @return mixed
18
     */
19 13
    public function handle($request, Closure $next)
20
    {
21 13
        if (config('lockout.enabled')) {
22
            // Check to see if this method and path is whitelisted
23 8
            foreach (config('lockout.whitelist') as $method => $path) {
24 1
                if ($request->isMethod($method) && $request->path() === $path) {
25 1
                    return $next($request);
26
                }
27
            }
28
            
29 8
            foreach (config('lockout.locked_types', []) as $type) {
30 7
                if ($request->isMethod('post') && config('lockout.allow_login')) {
31 1
                    abort_if($request->path() !== config('lockout.login_path') && $request->path() !== config('lockout.logout_path'), Response::HTTP_UNAUTHORIZED);
32 6
                } elseif ($request->isMethod(strtolower($type))) {
33 7
                    abort(Response::HTTP_UNAUTHORIZED);
34
                }
35
            }
36
37
            // Block any other specific get requests that may alter data
38 2
            if ($request->isMethod('get')) {
39 1
                collect(config('lockout.pages', []))
40
                    ->each(function ($item) use ($request) {
41 1
                        if ($request->path() === $item) {
42 1
                            abort(Response::HTTP_UNAUTHORIZED);
43
                        }
44 1
                    });
45
            }
46
        }
47
48 6
        return $next($request);
49
    }
50
}
51