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 EditableFormHeading extends EditableFormField |
||
| 17 | { |
||
| 18 | private static $singular_name = 'Heading'; |
||
| 19 | |||
| 20 | private static $plural_name = 'Headings'; |
||
| 21 | |||
| 22 | private static $literal = true; |
||
| 23 | |||
| 24 | private static $db = [ |
||
| 25 | 'Level' => 'Int(3)', // From CustomSettings |
||
| 26 | 'HideFromReports' => 'Boolean(0)' // from CustomSettings |
||
| 27 | ]; |
||
| 28 | |||
| 29 | private static $defaults = [ |
||
| 30 | 'Level' => 3, |
||
| 31 | 'HideFromReports' => false |
||
| 32 | ]; |
||
| 33 | |||
| 34 | private static $table_name = 'EditableFormHeading'; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @return FieldList |
||
| 38 | */ |
||
| 39 | public function getCMSFields() |
||
| 68 | |||
| 69 | public function getFormField() |
||
| 78 | |||
| 79 | View Code Duplication | protected function updateFormField($field) |
|
| 91 | |||
| 92 | public function showInReports() |
||
| 96 | |||
| 97 | public function getFieldValidationOptions() |
||
| 101 | |||
| 102 | public function getSelectorHolder() |
||
| 106 | |||
| 107 | public function getLevel() |
||
| 111 | } |
||
| 112 |