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 |
||
34 | class DNDataTransfer extends DataObject { |
||
35 | |||
36 | private static $db = array( |
||
37 | "ResqueToken" => "Varchar(255)", |
||
38 | // Observe that this is not the same as Resque status, since ResqueStatus is not persistent. |
||
39 | "Status" => "Enum('Queued, Started, Finished, Failed, n/a', 'n/a')", |
||
40 | "Direction" => "Enum('get, push', 'get')", |
||
41 | "Mode" => "Enum('all, assets, db', '')", |
||
42 | "Origin" => "Enum('EnvironmentTransfer,ManualUpload', 'EnvironmentTransfer')", |
||
43 | ); |
||
44 | |||
45 | private static $has_one = array( |
||
46 | "Environment" => "DNEnvironment", |
||
47 | "Author" => "Member", |
||
48 | "DataArchive" => "DNDataArchive", |
||
49 | "BackupDataTransfer" => "DNDataTransfer" // denotes an automated backup done for a push of this data transfer |
||
50 | ); |
||
51 | |||
52 | private static $singular_name = 'Data Transfer'; |
||
53 | |||
54 | private static $plural_name = 'Data Transfers'; |
||
55 | |||
56 | private static $summary_fields = array( |
||
57 | 'Created' => 'Created', |
||
58 | 'Author.Title' => 'Author', |
||
59 | 'Environment.Project.Name' => 'Project', |
||
60 | 'Environment.Name' => 'Environment', |
||
61 | 'Status' => 'Status', |
||
62 | 'Origin' => 'Origin', |
||
63 | ); |
||
64 | |||
65 | private static $searchable_fields = array( |
||
66 | 'Environment.Project.Name' => array( |
||
67 | 'title' => 'Project', |
||
68 | ), |
||
69 | 'Environment.Name' => array( |
||
70 | 'title' => 'Environment', |
||
71 | ), |
||
72 | 'Status' => array( |
||
73 | 'title' => 'Status', |
||
74 | ), |
||
75 | 'Origin' => array( |
||
76 | 'title' => 'Origin', |
||
77 | ), |
||
78 | 'Mode' => array( |
||
79 | 'title' => 'Mode', |
||
80 | ), |
||
81 | 'Direction' => array( |
||
82 | 'title' => 'Direction', |
||
83 | ), |
||
84 | ); |
||
85 | |||
86 | /** |
||
87 | * @param int $int |
||
88 | * @return string |
||
89 | */ |
||
90 | View Code Duplication | public static function map_resque_status($int) { |
|
100 | |||
101 | public function getTitle() { |
||
104 | |||
105 | public function Link() { |
||
108 | |||
109 | public function LogLink() { |
||
112 | |||
113 | public function getDefaultSearchContext() { |
||
120 | |||
121 | public function getCMSFields() { |
||
145 | |||
146 | /** |
||
147 | * Queue a transfer job |
||
148 | */ |
||
149 | public function start() { |
||
183 | |||
184 | /** |
||
185 | * @param Member|null $member |
||
186 | * @return bool |
||
187 | */ |
||
188 | public function canView($member = null) { |
||
191 | |||
192 | /** |
||
193 | * Return a path to the log file. |
||
194 | * @return string |
||
195 | */ |
||
196 | protected function logfile() { |
||
203 | |||
204 | /** |
||
205 | * @return \DeploynautLogFile |
||
206 | */ |
||
207 | public function log() { |
||
210 | |||
211 | /** |
||
212 | * @return string |
||
213 | */ |
||
214 | public function LogContent() { |
||
217 | |||
218 | public function getDescription() { |
||
234 | |||
235 | public function getModeNice() { |
||
242 | |||
243 | /** |
||
244 | * Is this transfer an automated backup of a push transfer? |
||
245 | * @return boolean |
||
246 | */ |
||
247 | public function IsBackupDataTransfer() { |
||
253 | |||
254 | /** |
||
255 | * Returns the status of the resque job |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | View Code Duplication | public function ResqueStatus() { |
|
276 | |||
277 | } |
||
278 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.