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 | abstract class AutoCompleteField implements WebField { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @param Parameter $parameter |
||
| 13 | * @return array With captions indexed by values |
||
| 14 | */ |
||
| 15 | protected abstract function getOptions(Parameter $parameter); |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @param Parameter $parameter |
||
| 19 | * @param array $serialized |
||
| 20 | * @return mixed |
||
| 21 | */ |
||
| 22 | public function inflate(Parameter $parameter, $serialized) { |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param Parameter $parameter |
||
| 28 | * @param mixed $value |
||
| 29 | * @return string |
||
| 30 | */ |
||
| 31 | public function render(Parameter $parameter, $value) { |
||
| 34 | |||
| 35 | protected function renderComboBox(Parameter $parameter, $value, $fieldNameSuffix = '', $options = []) { |
||
| 52 | |||
| 53 | private function renderOptions(Parameter $parameter, $value) { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @param Parameter $parameter |
||
| 69 | * @return array|\rtens\domin\delivery\web\Element[] |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function headElements(Parameter $parameter) { |
|
| 79 | } |