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 | ||
| 17 | abstract class AssetFormBuilder extends DefaultFormBuilder | ||
| 18 | { | ||
| 19 | |||
| 20 | /** | ||
| 21 | * Get raw HTML for image markup | ||
| 22 | * | ||
| 23 | * @return string | ||
| 24 | */ | ||
| 25 | protected function getIconMarkup() | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Gets the main tabs for the file edit form | ||
| 35 | * | ||
| 36 | * @return TabSet | ||
| 37 | */ | ||
| 38 | protected function getFormFieldTabs() | ||
| 44 | |||
| 45 | /** | ||
| 46 | * @return FormAction | ||
| 47 | */ | ||
| 48 | protected function getSaveAction() | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Get delete action, if this record is deletable | ||
| 61 | * | ||
| 62 | * @return FormAction | ||
| 63 | */ | ||
| 64 | View Code Duplication | protected function getDeleteAction() | |
| 74 | |||
| 75 | /** | ||
| 76 | * Build basic actions | ||
| 77 | * | ||
| 78 | * @return FieldList | ||
| 79 | */ | ||
| 80 | public function getFormActions() | ||
| 90 | |||
| 91 | public function getFormFields() | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Build "details" formfield tab | ||
| 111 | * | ||
| 112 | * @return Tab | ||
| 113 | */ | ||
| 114 | protected function getFormFieldDetailsTab() | ||
| 121 | } | ||
| 122 | 
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.