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 |
||
| 8 | class Component_checkbox |
||
| 9 | extends AbstractComponent |
||
|
|
|||
| 10 | implements ValueComponentInterface, |
||
| 11 | DisableableComponentInterface |
||
| 12 | { |
||
| 13 | public $name_template = '{{name}}[]'; |
||
| 14 | |||
| 15 | public $composite_name_template = '{{parent_name}}[{{name}}][]'; |
||
| 16 | |||
| 17 | public $component_type = 'checkbox'; |
||
| 18 | |||
| 19 | View Code Duplication | public function default_model() |
|
| 20 | { |
||
| 21 | return array( |
||
| 22 | 'name' => '', |
||
| 23 | 'id' => '', |
||
| 24 | 'disabled' => false, |
||
| 25 | 'required' => false, |
||
| 26 | 'readonly' => false, |
||
| 27 | 'data' => array(), |
||
| 28 | 'default' => array(), |
||
| 29 | 'show' => null |
||
| 30 | ); |
||
| 31 | } |
||
| 32 | |||
| 33 | public function required_arguments() |
||
| 37 | |||
| 38 | public function get_template_path() |
||
| 42 | } |