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