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 |
||
16 | class SocialiteController extends Controller |
||
17 | { |
||
18 | use RedirectsUsers; |
||
19 | |||
20 | /** |
||
21 | * Where to redirect users after login. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $redirectTo = '/'; |
||
26 | |||
27 | /** |
||
28 | * Redirect the user to the GitHub authentication page. |
||
29 | * |
||
30 | * @return Response |
||
31 | */ |
||
32 | public function redirectToProvider() |
||
36 | |||
37 | /** |
||
38 | * Obtain the user information from GitHub. |
||
39 | * |
||
40 | * @return Response |
||
|
|||
41 | */ |
||
42 | public function handleProviderCallback(Request $request) |
||
57 | |||
58 | /** |
||
59 | * The user has been authenticated. |
||
60 | * |
||
61 | * @param \Illuminate\Http\Request $request The request object. |
||
62 | * @param \Xetaravel\Models\User $user The user that has been logged in. |
||
63 | * |
||
64 | * @return void |
||
65 | */ |
||
66 | View Code Duplication | protected function authenticated(Request $request, $user) |
|
75 | |||
76 | /** |
||
77 | * Find the user if he exists or create it. |
||
78 | * |
||
79 | * @param \Laravel\Socialite\Two\User $providerUser |
||
80 | * |
||
81 | * @return \Xetaravel\Models\User |
||
82 | */ |
||
83 | protected function findOrCreateUser(ProviderUser $providerUser): User |
||
104 | |||
105 | /** |
||
106 | * The user has been registered. |
||
107 | * |
||
108 | * @param \Xetaravel\Models\User $user The user that has been registered. |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | View Code Duplication | protected function registered(User $user) |
|
124 | } |
||
125 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.