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 | class CopyFactoryLog extends DataObject |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * we can write faster to MyISAM? |
||
14 | * |
||
15 | */ |
||
16 | private static $create_table_options = array( |
||
|
|||
17 | 'MySQLDatabase' => 'ENGINE=MyISAM' |
||
18 | ); |
||
19 | |||
20 | private static $db = array( |
||
21 | "StartTime" => "SS_Datetime", |
||
22 | "Type" => "Enum('Unknown,Fake,Real', 'Unknown')", |
||
23 | "CopyCausingClassName" => "Varchar(200)", |
||
24 | "CopyCausingClassNameID" => "Int", |
||
25 | "CopyFromClassNameID" => "Int", |
||
26 | "CopyIntoClassName" => "Varchar(200)", |
||
27 | "CopyIntoClassNameID" => "Int", |
||
28 | "Action" => "Text" |
||
29 | ); |
||
30 | |||
31 | private static $indexes = array( |
||
32 | "CopyCausingClassName" => true, |
||
33 | "CopyCausingClassNameID" => true, |
||
34 | "CopyFromClassNameID" => true, |
||
35 | "CopyIntoClassName" => true, |
||
36 | "CopyIntoClassNameID" => true |
||
37 | ); |
||
38 | |||
39 | private static $summary_fields = array( |
||
40 | "StartTime", |
||
41 | "Type", |
||
42 | "CopyCause", |
||
43 | "CopyFrom", |
||
44 | "CopyInto", |
||
45 | "FormattedShortAction" |
||
46 | ); |
||
47 | |||
48 | private static $field_labels = array( |
||
49 | "StartTime" => "Started", |
||
50 | "Type" => "Real or Fake", |
||
51 | "CopyCause" => "Started by", |
||
52 | "CopyFrom" => "From", |
||
53 | "CopyInto" => "Into", |
||
54 | "Action" => "Description" |
||
55 | ); |
||
56 | |||
57 | private static $searchable_fields = array( |
||
58 | "Type" => "PartialMatchFilter", |
||
59 | "Action" => "PartialMatchFilter" |
||
60 | ); |
||
61 | |||
62 | private static $casting = array( |
||
63 | "CopyCause" => "Varchar", |
||
64 | "CopyFrom" => "Varchar", |
||
65 | "CopyInto" => "Varchar", |
||
66 | "FormattedShortAction" => "HTMLText" |
||
67 | ); |
||
68 | |||
69 | private static $default_sort = "Created ASC"; |
||
70 | |||
71 | public function canEdit($member = null) |
||
75 | |||
76 | public function canDelete($member = null) |
||
80 | |||
81 | public function getCMSFields() |
||
120 | |||
121 | /** |
||
122 | * Copy Causer Description |
||
123 | * @casted |
||
124 | * @return Str |
||
125 | */ |
||
126 | View Code Duplication | public function getCopyCause() |
|
137 | |||
138 | /** |
||
139 | * Copy From Description |
||
140 | * @casted |
||
141 | * @return Str |
||
142 | */ |
||
143 | View Code Duplication | public function getCopyFrom() |
|
154 | |||
155 | /** |
||
156 | * Copy Into Description |
||
157 | * @casted |
||
158 | * @return Str |
||
159 | */ |
||
160 | View Code Duplication | public function getCopyInto() |
|
171 | |||
172 | |||
173 | /** |
||
174 | * Copy Into Description |
||
175 | * @casted |
||
176 | * @return Str |
||
177 | */ |
||
178 | public function getFormattedShortAction() |
||
182 | } |
||
183 |