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_switch |
||
9 | extends AbstractComponent |
||
|
|||
10 | implements ValueComponentInterface, |
||
11 | DisableableComponentInterface, |
||
12 | FilterableComponentInterface |
||
13 | { |
||
14 | public $component_type = 'switch'; |
||
15 | |||
16 | View Code Duplication | public function default_model() |
|
17 | { |
||
18 | return array( |
||
19 | 'name' => '', |
||
20 | 'id' => '', |
||
21 | 'disabled' => false, |
||
22 | 'readonly' => false, |
||
23 | 'default' => 'off', |
||
24 | 'filter' => array( $this, 'filter' ), |
||
25 | 'show' => null |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | public function required_arguments() |
||
33 | |||
34 | public function get_template_path() |
||
38 | |||
39 | /** |
||
40 | * This filter is needed when the form is submitted without $.amarkalUIForm, |
||
41 | * since the value of the checkbox becomes NULL when it is unchecked. When using |
||
42 | * $.amarkalUIForm to submit the form, the component's getValue/setValue will |
||
43 | * handle this. |
||
44 | * |
||
45 | * @param [string] $v |
||
46 | * @return void |
||
47 | */ |
||
48 | public function filter($v) |
||
53 | } |