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 | View Code Duplication | class AdminController extends FlareController |
|
|
|||
17 | { |
||
18 | use AuthenticatesUsers, RegistersUsers { |
||
19 | AuthenticatesUsers::redirectPath insteadof RegistersUsers; |
||
20 | } |
||
21 | use ThrottlesLogins; |
||
22 | use RegistersUsers; |
||
23 | use DispatchesJobs; |
||
24 | |||
25 | /** |
||
26 | * Auth. |
||
27 | * |
||
28 | * @var Guard |
||
29 | */ |
||
30 | protected $auth; |
||
31 | |||
32 | /** |
||
33 | * __construct. |
||
34 | * |
||
35 | * @param Guard $auth |
||
36 | * @param AdminManager $adminManager |
||
37 | */ |
||
38 | public function __construct(Guard $auth, AdminManager $adminManager) |
||
44 | |||
45 | /** |
||
46 | * Show the Dashboard. |
||
47 | * |
||
48 | * @return \Illuminate\Http\Response |
||
49 | */ |
||
50 | public function getDashboard() |
||
60 | |||
61 | /** |
||
62 | * Show the login form. |
||
63 | * |
||
64 | * @return \Illuminate\Http\Response |
||
65 | */ |
||
66 | public function getLogin() |
||
70 | |||
71 | /** |
||
72 | * Log the user. |
||
73 | * |
||
74 | * @return \Illuminate\Http\RedirectReponse |
||
75 | */ |
||
76 | public function getLogout() |
||
82 | |||
83 | /** |
||
84 | * Display the form to request a password reset link. |
||
85 | * |
||
86 | * @return \Illuminate\Http\Response |
||
87 | */ |
||
88 | public function getEmail() |
||
92 | |||
93 | /** |
||
94 | * Display the form to request a password reset link. |
||
95 | * |
||
96 | * @return \Illuminate\Http\Response |
||
97 | */ |
||
98 | public function getReset() |
||
102 | |||
103 | /** |
||
104 | * Performs the login redirect action. |
||
105 | * |
||
106 | * If the authenticated user has admin permissions |
||
107 | * then they will be redirected into the admin |
||
108 | * panel. If they do no, they will be sent |
||
109 | * to the homepage of the website. |
||
110 | * |
||
111 | * @return \Illuminate\Http\RedirectReponse |
||
112 | */ |
||
113 | protected function loginRedirect() |
||
121 | |||
122 | /** |
||
123 | * Method is called when the appropriate controller |
||
124 | * method is unable to be found or called. |
||
125 | * |
||
126 | * @param array $parameters |
||
127 | * |
||
128 | * @return \Illuminate\Http\Response |
||
129 | */ |
||
130 | public function missingMethod($parameters = array()) |
||
134 | } |
||
135 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.