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 |
||
25 | class JqadmController extends AdminController |
||
26 | { |
||
27 | use AuthorizesRequests; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * Returns the JS file content |
||
32 | * |
||
33 | * @return \Illuminate\Http\Response Response object containing the generated output |
||
34 | */ |
||
35 | public function fileAction() |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Returns the HTML code for a copy of a resource object |
||
77 | * |
||
78 | * @return string Generated output |
||
79 | */ |
||
80 | View Code Duplication | public function copyAction() |
|
89 | |||
90 | |||
91 | /** |
||
92 | * Returns the HTML code for a new resource object |
||
93 | * |
||
94 | * @return string Generated output |
||
95 | */ |
||
96 | View Code Duplication | public function createAction() |
|
105 | |||
106 | |||
107 | /** |
||
108 | * Deletes the resource object or a list of resource objects |
||
109 | * |
||
110 | * @return string Generated output |
||
111 | */ |
||
112 | View Code Duplication | public function deleteAction() |
|
121 | |||
122 | |||
123 | /** |
||
124 | * Returns the HTML code for the requested resource object |
||
125 | * |
||
126 | * @return string Generated output |
||
127 | */ |
||
128 | View Code Duplication | public function getAction() |
|
137 | |||
138 | |||
139 | /** |
||
140 | * Saves a new resource object |
||
141 | * |
||
142 | * @return string Generated output |
||
143 | */ |
||
144 | View Code Duplication | public function saveAction() |
|
153 | |||
154 | |||
155 | /** |
||
156 | * Returns the HTML code for a list of resource objects |
||
157 | * |
||
158 | * @return string Generated output |
||
159 | */ |
||
160 | View Code Duplication | public function searchAction() |
|
169 | |||
170 | |||
171 | /** |
||
172 | * Returns the resource controller |
||
173 | * |
||
174 | * @return \Aimeos\Admin\JQAdm\Iface JQAdm client |
||
175 | */ |
||
176 | protected function createClient() |
||
193 | |||
194 | |||
195 | /** |
||
196 | * Returns the generated HTML code |
||
197 | * |
||
198 | * @param string $content Content from admin client |
||
199 | * @return \Illuminate\Contracts\View\View View for rendering the output |
||
200 | */ |
||
201 | protected function getHtml( $content ) |
||
208 | |||
209 | |||
210 | /** |
||
211 | * Sets the locale item in the given context |
||
212 | * |
||
213 | * @param \Aimeos\MShop\Context\Item\Iface $context Context object |
||
214 | * @param string $site Unique site code |
||
215 | * @param string $lang ISO language code, e.g. "en" or "en_GB" |
||
216 | * @return \Aimeos\MShop\Context\Item\Iface Modified context object |
||
217 | */ |
||
218 | View Code Duplication | protected function setLocale( \Aimeos\MShop\Context\Item\Iface $context, $site, $lang ) |
|
238 | } |
||
239 |
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.