Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
22 | class SocialiteController extends Controller |
||
23 | { |
||
24 | use RedirectsUsers; |
||
25 | |||
26 | /** |
||
27 | * Where to redirect users after login. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $redirectTo = '/'; |
||
32 | |||
33 | /** |
||
34 | * The driver used. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $driver; |
||
39 | |||
40 | /** |
||
41 | * Show the registration form. |
||
42 | * |
||
43 | * @param \Illuminate\Http\Request $request The request object. |
||
44 | * @param string $driver The driver used. |
||
45 | * |
||
46 | * @return \Illuminate\View\View |
||
47 | */ |
||
48 | public function showRegistrationForm(Request $request, string $driver): View |
||
52 | |||
53 | /** |
||
54 | * Register an user that has been forced to modify his email or |
||
55 | * username due to a conflit with the database. |
||
56 | * |
||
57 | * @param \Illuminate\Http\Request $request The request object. |
||
58 | * @param string $driver The driver used. |
||
59 | * |
||
60 | * @return \Illuminate\Http\RedirectResponse |
||
61 | */ |
||
62 | public function register(Request $request, string $driver): RedirectResponse |
||
84 | |||
85 | /** |
||
86 | * Redirect the user to the Provider authentication page. |
||
87 | * |
||
88 | * @param \Illuminate\Http\Request $request The request object. |
||
89 | * @param string $driver The driver used. |
||
90 | * @param string $type The type of callback. (Either `login` or `register`) |
||
91 | * |
||
92 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
93 | */ |
||
94 | public function redirectToProvider(Request $request, string $driver, string $type): RedirectResponseSF |
||
100 | |||
101 | /** |
||
102 | * Obtain the user information from the Provider and process to the |
||
103 | * registration or login regarding to the type of callback. |
||
104 | * |
||
105 | * @param \Illuminate\Http\Request $request The request object. |
||
106 | * @param string $driver The driver used. |
||
107 | * @param string $type The type of callback. (Either `login` or `register`) |
||
108 | * |
||
109 | * @return \Illuminate\Http\Response |
||
110 | */ |
||
111 | public function handleProviderCallback(Request $request, string $driver, string $type): RedirectResponse |
||
148 | |||
149 | /** |
||
150 | * Login the user and trigger the authenticated function. |
||
151 | * |
||
152 | * @param \Illuminate\Http\Request $request The request object. |
||
153 | * @param \Xetaravel\Models\User $user The user to login. |
||
154 | * |
||
155 | * @return \Illuminate\Http\RedirectResponse |
||
156 | */ |
||
157 | protected function login(Request $request, User $user): RedirectResponse |
||
165 | |||
166 | /** |
||
167 | * Handle the registration. |
||
168 | * |
||
169 | * @param \Illuminate\Http\Request $request The request object. |
||
170 | * @param \Laravel\Socialite\Two\User $user The user to register. |
||
171 | * |
||
172 | * @return \Illuminate\Http\RedirectResponse|\Xetaravel\Models\User |
||
173 | */ |
||
174 | protected function handleRegister(Request $request, ProviderUser $user) |
||
210 | |||
211 | /** |
||
212 | * Create the user. |
||
213 | * |
||
214 | * @param \Laravel\Socialite\Two\User $user The user to create. |
||
215 | * |
||
216 | * @return \Xetaravel\Models\User |
||
217 | */ |
||
218 | protected function createUser(ProviderUser $user) |
||
231 | |||
232 | /** |
||
233 | * The user has been authenticated. |
||
234 | * |
||
235 | * @param \Illuminate\Http\Request $request The request object. |
||
236 | * @param \Xetaravel\Models\User $user The user that has been logged in. |
||
237 | * |
||
238 | * @return void |
||
239 | */ |
||
240 | View Code Duplication | protected function authenticated(Request $request, $user) |
|
249 | |||
250 | /** |
||
251 | * The user has been registered. |
||
252 | * |
||
253 | * @param \Laravel\Socialite\Two\User $user The user that has been registered. |
||
254 | * |
||
255 | * @return \Xetaravel\Models\User |
||
256 | */ |
||
257 | protected function registered(ProviderUser $user): User |
||
273 | } |
||
274 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.