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 |
||
7 | class Nav_Menu_Datastore extends Post_Meta_Datastore { |
||
8 | |||
9 | public function get_garbage_prefix() { |
||
15 | |||
16 | public function get_clean_field_name( $field ) { |
||
20 | |||
21 | public function get_dirty_field_name( $field ) { |
||
25 | |||
26 | /** |
||
27 | * Save the field value(s) into the database. |
||
28 | * |
||
29 | * @param Field $field The field to save. |
||
30 | */ |
||
31 | public function save( Field $field ) { |
||
36 | |||
37 | /** |
||
38 | * Load the field value(s) from the database. |
||
39 | * |
||
40 | * @param Field $field The field to retrieve value for. |
||
41 | */ |
||
42 | public function load( Field $field ) { |
||
65 | |||
66 | /** |
||
67 | * Delete the field value(s) from the database. |
||
68 | * |
||
69 | * @param Field $field The field to delete. |
||
70 | */ |
||
71 | public function delete( Field $field ) { |
||
74 | |||
75 | /** |
||
76 | * Load complex field value(s) from the database. |
||
77 | * |
||
78 | * @param mixed $field The field to load values for. |
||
79 | */ |
||
80 | public function load_values( $field ) { |
||
101 | |||
102 | /** |
||
103 | * Delete complex field value(s) from the database. |
||
104 | * |
||
105 | * @param mixed $field The field to delete values for. |
||
106 | */ |
||
107 | View Code Duplication | public function delete_values( $field ) { |
|
120 | } |
||
121 |