Conditions | 13 |
Paths | 24 |
Total Lines | 59 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
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 |
||
23 | public function handle($request, Closure $next) |
||
24 | { |
||
25 | if (config('settings.activation')) { |
||
26 | $user = Auth::user(); |
||
27 | $currentRoute = Route::currentRouteName(); |
||
28 | $routesAllowed = [ |
||
29 | 'activation-required', |
||
30 | 'activate/{token}', |
||
31 | 'activate', |
||
32 | 'activation', |
||
33 | 'exceeded', |
||
34 | 'authenticated.activate', |
||
35 | 'authenticated.activation-resend', |
||
36 | 'logout', |
||
37 | 'welcome', |
||
38 | ]; |
||
39 | |||
40 | if (!in_array($currentRoute, $routesAllowed)) { |
||
41 | if ($user && $user->activated != 1) { |
||
|
|||
42 | Log::info('Non-activated user attempted to visit '.$currentRoute.'. ', [$user]); |
||
43 | |||
44 | return redirect()->route('activation-required') |
||
45 | ->with([ |
||
46 | 'message' => 'Activation is required. ', |
||
47 | 'status' => 'danger', |
||
48 | ]); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | if ($user && $user->activated != 1) { |
||
53 | $activationsCount = Activation::where('user_id', $user->id) |
||
54 | ->where('created_at', '>=', Carbon::now()->subHours(config('settings.timePeriod'))) |
||
55 | ->count(); |
||
56 | |||
57 | if ($activationsCount >= config('settings.maxAttempts')) { |
||
58 | return redirect()->route('exceeded'); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | if (in_array($currentRoute, $routesAllowed)) { |
||
63 | if ($user && $user->activated == 1) { |
||
64 | Log::info('Activated user attempted to visit '.$currentRoute.'. ', [$user]); |
||
65 | |||
66 | if ($user->isAdmin()) { |
||
67 | return redirect('home'); |
||
68 | } |
||
69 | |||
70 | return redirect('home'); |
||
71 | } |
||
72 | |||
73 | if (!$user) { |
||
74 | Log::info('Non registered visit to '.$currentRoute.'. '); |
||
75 | |||
76 | return redirect()->route('welcome'); |
||
77 | } |
||
78 | } |
||
79 | } |
||
80 | |||
81 | return $next($request); |
||
82 | } |
||
84 |