| Conditions | 12 |
| Paths | 4 |
| Total Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 12 |
| Changes | 0 | ||
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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 |