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 |
||
16 | class DNCreateEnvironment extends DataObject { |
||
|
|||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private static $db = array( |
||
22 | 'Data' => 'Text', |
||
23 | 'ResqueToken' => 'Varchar(255)', |
||
24 | "Status" => "Enum('Queued, Started, Finished, Failed, n/a', 'n/a')", |
||
25 | 'IsInitialEnvironment' => 'Boolean', |
||
26 | ); |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | private static $has_one = array( |
||
32 | 'Project' => 'DNProject', |
||
33 | 'Creator' => 'Member' |
||
34 | ); |
||
35 | |||
36 | /** |
||
37 | * |
||
38 | * @param int $int |
||
39 | * @return string |
||
40 | */ |
||
41 | View Code Duplication | public static function map_resque_status($int) { |
|
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | public function Name() { |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function Link() { |
||
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | public function LogLink() { |
||
73 | |||
74 | /** |
||
75 | * @return boolean |
||
76 | */ |
||
77 | public function canView($member = null) { |
||
80 | |||
81 | /** |
||
82 | * Return a path to the log file. |
||
83 | * @return string |
||
84 | */ |
||
85 | protected function logfile() { |
||
92 | |||
93 | /** |
||
94 | * @return \DeploynautLogFile |
||
95 | */ |
||
96 | public function log() { |
||
99 | |||
100 | public function LogContent() { |
||
103 | |||
104 | /** |
||
105 | * Returns the status of the resque job |
||
106 | * |
||
107 | * @return string |
||
108 | */ |
||
109 | View Code Duplication | public function ResqueStatus() { |
|
126 | |||
127 | /** |
||
128 | * Start a resque job for this creation. |
||
129 | * |
||
130 | * @return string Resque token |
||
131 | */ |
||
132 | protected function enqueueCreation() { |
||
160 | |||
161 | public function start() { |
||
162 | $log = $this->log(); |
||
163 | $token = $this->enqueueCreation(); |
||
164 | $this->ResqueToken = $token; |
||
165 | $this->Status = 'Queued'; |
||
166 | $this->write(); |
||
167 | |||
168 | $message = sprintf('Environment creation queued as job %s', $token); |
||
169 | $log->write($message); |
||
170 | } |
||
171 | |||
172 | public function createEnvironment() { |
||
179 | |||
180 | /** |
||
181 | * Fetches the EnvironmentCreateBackend based on the EnvironmentType saved to this job. |
||
182 | * |
||
183 | * @return EnvironmentCreateBackend|null |
||
184 | * @throws Exception |
||
185 | */ |
||
186 | public function getBackend() { |
||
198 | } |
||
199 | |||
200 |
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
.