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 |
||
| 6 | class DNBranchList extends ArrayList { |
||
|
|
|||
| 7 | |||
| 8 | /** |
||
| 9 | * @var string |
||
| 10 | */ |
||
| 11 | protected static $refs_dir = ''; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @var bool |
||
| 15 | */ |
||
| 16 | protected $loaded = false; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var array |
||
| 20 | */ |
||
| 21 | protected $builds = array(); |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var DNProject |
||
| 25 | */ |
||
| 26 | protected $project; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var DNData |
||
| 30 | */ |
||
| 31 | protected $data; |
||
| 32 | |||
| 33 | public static function set_refs_dir($refsDir) { |
||
| 36 | |||
| 37 | public static function get_refs_dir() { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @param \DNProject $project |
||
| 43 | * @param \DNData $data |
||
| 44 | */ |
||
| 45 | public function __construct(\DNProject $project, \DNData $data) { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @return array |
||
| 53 | */ |
||
| 54 | protected function getReferences() { |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Find a branch in this set by branch name. |
||
| 83 | * |
||
| 84 | * @param $name |
||
| 85 | * |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | public function byName($name) { |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Returns an Iterator for this ArrayList. |
||
| 102 | * This function allows you to use ArrayList in foreach loops |
||
| 103 | * |
||
| 104 | * @return ArrayIterator |
||
| 105 | */ |
||
| 106 | View Code Duplication | public function getIterator() { |
|
| 118 | } |
||
| 119 |
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.