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 | "IncludeResampled" => "Boolean", |
||
| 44 | ); |
||
| 45 | |||
| 46 | private static $has_one = array( |
||
| 47 | "Environment" => "DNEnvironment", |
||
| 48 | "Author" => "Member", |
||
| 49 | "DataArchive" => "DNDataArchive", |
||
| 50 | "BackupDataTransfer" => "DNDataTransfer" // denotes an automated backup done for a push of this data transfer |
||
| 51 | ); |
||
| 52 | |||
| 53 | private static $singular_name = 'Data Transfer'; |
||
| 54 | |||
| 55 | private static $plural_name = 'Data Transfers'; |
||
| 56 | |||
| 57 | private static $summary_fields = array( |
||
| 58 | 'Created' => 'Created', |
||
| 59 | 'Author.Title' => 'Author', |
||
| 60 | 'Environment.Project.Name' => 'Project', |
||
| 61 | 'Environment.Name' => 'Environment', |
||
| 62 | 'Status' => 'Status', |
||
| 63 | 'Origin' => 'Origin', |
||
| 64 | 'IncludeResampled.Nice' => 'Included Resampled?', |
||
| 65 | ); |
||
| 66 | |||
| 67 | private static $searchable_fields = array( |
||
| 68 | 'Environment.Project.Name' => array( |
||
| 69 | 'title' => 'Project', |
||
| 70 | ), |
||
| 71 | 'Environment.Name' => array( |
||
| 72 | 'title' => 'Environment', |
||
| 73 | ), |
||
| 74 | 'Status' => array( |
||
| 75 | 'title' => 'Status', |
||
| 76 | ), |
||
| 77 | 'Origin' => array( |
||
| 78 | 'title' => 'Origin', |
||
| 79 | ), |
||
| 80 | 'Mode' => array( |
||
| 81 | 'title' => 'Mode', |
||
| 82 | ), |
||
| 83 | 'Direction' => array( |
||
| 84 | 'title' => 'Direction', |
||
| 85 | ), |
||
| 86 | ); |
||
| 87 | |||
| 88 | /** |
||
| 89 | * When running the transfer, should a backup be performed before pushing the data? |
||
| 90 | * @var bool |
||
| 91 | */ |
||
| 92 | protected $backupBeforePush = true; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param int $int |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | View Code Duplication | public static function map_resque_status($int) { |
|
| 108 | |||
| 109 | /** |
||
| 110 | * @param boolean $value |
||
| 111 | */ |
||
| 112 | public function setBackupBeforePush($value) { |
||
| 115 | |||
| 116 | public function getTitle() { |
||
| 119 | |||
| 120 | public function Link() { |
||
| 123 | |||
| 124 | public function LogLink() { |
||
| 127 | |||
| 128 | public function getDefaultSearchContext() { |
||
| 135 | |||
| 136 | public function getCMSFields() { |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Queue a transfer job |
||
| 163 | */ |
||
| 164 | public function start() { |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param Member|null $member |
||
| 203 | * @return bool |
||
| 204 | */ |
||
| 205 | public function canView($member = null) { |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Return a path to the log file. |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | protected function logfile() { |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return \DeploynautLogFile |
||
| 223 | */ |
||
| 224 | public function log() { |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return string |
||
| 230 | */ |
||
| 231 | public function LogContent() { |
||
| 234 | |||
| 235 | public function getDescription() { |
||
| 251 | |||
| 252 | public function getModeNice() { |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Is this transfer an automated backup prior to a push transfer or deployment? |
||
| 262 | * @return boolean |
||
| 263 | */ |
||
| 264 | public function IsBackupDataTransfer() { |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Returns the status of the resque job |
||
| 286 | * |
||
| 287 | * @return string |
||
| 288 | */ |
||
| 289 | View Code Duplication | public function ResqueStatus() { |
|
| 306 | |||
| 307 | } |
||
| 308 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.