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 |
||
12 | class DNPing extends DataObject { |
||
|
|||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | private static $db = array( |
||
18 | "ResqueToken" => "Varchar(255)", |
||
19 | ); |
||
20 | |||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | private static $has_one = array( |
||
25 | "Environment" => "DNEnvironment", |
||
26 | "Deployer" =>"Member", |
||
27 | ); |
||
28 | |||
29 | /** |
||
30 | * @return string |
||
31 | */ |
||
32 | public function Link() { |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | public function LogLink() { |
||
42 | |||
43 | /** |
||
44 | * @param Member|null $member |
||
45 | * @return bool |
||
46 | */ |
||
47 | public function canView($member = null) { |
||
50 | |||
51 | /** |
||
52 | * Return a path to the log file. |
||
53 | * @return string |
||
54 | */ |
||
55 | protected function logfile() { |
||
62 | |||
63 | /** |
||
64 | * @return \DeploynautLogFile |
||
65 | */ |
||
66 | public function log() { |
||
69 | |||
70 | /** |
||
71 | * @return string |
||
72 | */ |
||
73 | public function LogContent() { |
||
76 | |||
77 | /** |
||
78 | * @return string |
||
79 | */ |
||
80 | View Code Duplication | public function ResqueStatus() { |
|
93 | |||
94 | /** |
||
95 | * Queue a ping job |
||
96 | */ |
||
97 | public function start() { |
||
132 | } |
||
133 |
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
.