Conditions | 5 |
Paths | 4 |
Total Lines | 54 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
96 | public function verify2fa(Request $request): RedirectResponse |
||
97 | { |
||
98 | $request->validate([ |
||
99 | 'one_time_password' => 'required|numeric', |
||
100 | ]); |
||
101 | |||
102 | // Get the user ID from session |
||
103 | if (! $request->session()->has('2fa:user:id')) { |
||
104 | return redirect()->route('login') |
||
105 | ->with('message', 'The two-factor authentication session has expired. Please login again.') |
||
106 | ->with('message_type', 'danger'); |
||
107 | } |
||
108 | |||
109 | $userId = $request->session()->get('2fa:user:id'); |
||
110 | $user = \App\Models\User::find($userId); |
||
111 | |||
112 | if (! $user || ! $user->passwordSecurity) { |
||
113 | $request->session()->forget('2fa:user:id'); |
||
114 | |||
115 | return redirect()->route('login') |
||
116 | ->with('message', 'User not found or 2FA not configured. Please login again.') |
||
117 | ->with('message_type', 'danger'); |
||
118 | } |
||
119 | |||
120 | // Verify the OTP code |
||
121 | $valid = \Google2FA::verifyKey( |
||
122 | $user->passwordSecurity->google2fa_secret, |
||
123 | $request->input('one_time_password') |
||
124 | ); |
||
125 | |||
126 | if (! $valid) { |
||
127 | return redirect()->route('2fa.verify') |
||
128 | ->with('message', 'Invalid authentication code. Please try again.') |
||
129 | ->with('message_type', 'danger'); |
||
130 | } |
||
131 | |||
132 | // Log the user back in |
||
133 | Auth::login($user); |
||
134 | |||
135 | // Mark the user as having passed 2FA |
||
136 | session([config('google2fa.session_var') => true]); |
||
137 | |||
138 | // Store the timestamp for determining how long the 2FA session is valid |
||
139 | session([config('google2fa.session_var').'.auth.passed_at' => time()]); |
||
140 | |||
141 | // Clean up the temporary session variable |
||
142 | $request->session()->forget('2fa:user:id'); |
||
143 | |||
144 | // Determine where to redirect after successful verification |
||
145 | $redirectUrl = $request->session()->pull('url.intended', '/'); |
||
146 | |||
147 | return redirect()->to($redirectUrl) |
||
148 | ->with('message', 'Two-factor authentication verified successfully.') |
||
149 | ->with('message_type', 'success'); |
||
150 | } |
||
186 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths