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 |
||
9 | class CampaignAdmin extends LeftAndMain implements PermissionProvider { |
||
10 | |||
11 | private static $allowed_actions = [ |
||
|
|||
12 | 'set', |
||
13 | 'sets', |
||
14 | 'schema', |
||
15 | 'DetailEditForm', |
||
16 | 'readCampaigns', |
||
17 | 'createCampaign', |
||
18 | 'readCampaign', |
||
19 | 'updateCampaign', |
||
20 | 'deleteCampaign', |
||
21 | ]; |
||
22 | |||
23 | private static $menu_priority = 11; |
||
24 | |||
25 | private static $menu_title = 'Campaigns'; |
||
26 | |||
27 | private static $url_handlers = [ |
||
28 | 'GET sets' => 'readCampaigns', |
||
29 | 'POST set/$ID' => 'createCampaign', |
||
30 | 'GET set/$ID' => 'readCampaign', |
||
31 | 'PUT set/$ID' => 'updateCampaign', |
||
32 | 'DELETE set/$ID' => 'deleteCampaign', |
||
33 | ]; |
||
34 | |||
35 | private static $url_segment = 'campaigns'; |
||
36 | |||
37 | public function getClientConfig() { |
||
47 | |||
48 | public function schema($request) { |
||
163 | |||
164 | /** |
||
165 | * REST endpoint to create a campaign. |
||
166 | * |
||
167 | * @param SS_HTTPRequest $request |
||
168 | * |
||
169 | * @return SS_HTTPResponse |
||
170 | */ |
||
171 | View Code Duplication | public function createCampaign(SS_HTTPRequest $request) { |
|
180 | |||
181 | /** |
||
182 | * REST endpoint to get a list of campaigns. |
||
183 | * |
||
184 | * @param SS_HTTPRequest $request |
||
185 | * |
||
186 | * @return SS_HTTPResponse |
||
187 | */ |
||
188 | public function readCampaigns(SS_HTTPRequest $request) { |
||
195 | |||
196 | /** |
||
197 | * Get list contained as a hal wrapper |
||
198 | * |
||
199 | * @return array |
||
200 | */ |
||
201 | protected function getListResource() { |
||
221 | |||
222 | /** |
||
223 | * Build item resource from a changeset |
||
224 | * |
||
225 | * @param ChangeSet $changeSet |
||
226 | * @return array |
||
227 | */ |
||
228 | protected function getChangeSetResource(ChangeSet $changeSet) { |
||
253 | |||
254 | /** |
||
255 | * Build item resource from a changesetitem |
||
256 | * |
||
257 | * @param ChangeSetItem $changeSetItem |
||
258 | * @return array |
||
259 | */ |
||
260 | protected function getChangeSetItemResource(ChangeSetItem $changeSetItem) { |
||
291 | |||
292 | |||
293 | |||
294 | /** |
||
295 | * Gets viewable list of campaigns |
||
296 | * |
||
297 | * @return SS_List |
||
298 | */ |
||
299 | protected function getListItems() { |
||
306 | |||
307 | |||
308 | /** |
||
309 | * REST endpoint to get a campaign. |
||
310 | * |
||
311 | * @param SS_HTTPRequest $request |
||
312 | * |
||
313 | * @return SS_HTTPResponse |
||
314 | */ |
||
315 | public function readCampaign(SS_HTTPRequest $request) { |
||
324 | |||
325 | /** |
||
326 | * REST endpoint to update a campaign. |
||
327 | * |
||
328 | * @param SS_HTTPRequest $request |
||
329 | * |
||
330 | * @return SS_HTTPResponse |
||
331 | */ |
||
332 | View Code Duplication | public function updateCampaign(SS_HTTPRequest $request) { |
|
341 | |||
342 | /** |
||
343 | * REST endpoint to delete a campaign. |
||
344 | * |
||
345 | * @param SS_HTTPRequest $request |
||
346 | * |
||
347 | * @return SS_HTTPResponse |
||
348 | */ |
||
349 | public function deleteCampaign(SS_HTTPRequest $request) { |
||
371 | |||
372 | /** |
||
373 | * @todo Use GridFieldDetailForm once it can handle structured data and form schemas |
||
374 | * |
||
375 | * @return Form |
||
376 | */ |
||
377 | public function getDetailEditForm() { |
||
387 | |||
388 | /** |
||
389 | * Gets user-visible url to edit a specific {@see ChangeSet} |
||
390 | * |
||
391 | * @param $itemID |
||
392 | * @return string |
||
393 | */ |
||
394 | public function SetLink($itemID) { |
||
400 | |||
401 | /** |
||
402 | * Gets user-visible url to edit a specific {@see ChangeSetItem} |
||
403 | * |
||
404 | * @param int $itemID |
||
405 | * @return string |
||
406 | */ |
||
407 | public function ItemLink($itemID) { |
||
413 | |||
414 | /** |
||
415 | * |
||
416 | */ |
||
417 | public function FindReferencedChanges() { |
||
420 | |||
421 | } |
||
422 |