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 |
||
| 18 | class EditableNumericField extends EditableFormField |
||
| 19 | { |
||
| 20 | |||
| 21 | private static $singular_name = 'Numeric Field'; |
||
| 22 | |||
| 23 | private static $plural_name = 'Numeric Fields'; |
||
| 24 | |||
| 25 | private static $has_placeholder = true; |
||
| 26 | |||
| 27 | private static $db = [ |
||
| 28 | 'MinValue' => 'Int', |
||
| 29 | 'MaxValue' => 'Int' |
||
| 30 | ]; |
||
| 31 | |||
| 32 | private static $table_name = 'EditableNumericField'; |
||
| 33 | |||
| 34 | public function getSetsOwnError() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return NumericField |
||
| 41 | */ |
||
| 42 | View Code Duplication | public function getFormField() |
|
| 53 | |||
| 54 | View Code Duplication | public function getFieldValidationOptions() |
|
| 67 | |||
| 68 | /** |
||
| 69 | * Updates a formfield with the additional metadata specified by this field |
||
| 70 | * |
||
| 71 | * @param FormField $field |
||
| 72 | */ |
||
| 73 | protected function updateFormField($field) |
||
| 85 | } |
||
| 86 |