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 |
||
| 24 | class PedigreeField |
||
|
|
|||
| 25 | { |
||
| 26 | protected $id; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @param $fieldnumber |
||
| 30 | * @param $config |
||
| 31 | */ |
||
| 32 | View Code Duplication | public function __construct($fieldnumber, $config) |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @return bool |
||
| 49 | */ |
||
| 50 | public function isActive() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @return bool |
||
| 57 | */ |
||
| 58 | public function inAdvanced() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @return bool |
||
| 65 | */ |
||
| 66 | public function isLocked() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return bool |
||
| 73 | */ |
||
| 74 | public function hasSearch() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return bool |
||
| 81 | */ |
||
| 82 | public function addLitter() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return bool |
||
| 89 | */ |
||
| 90 | public function generalLitter() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @return bool |
||
| 97 | */ |
||
| 98 | public function hasLookup() |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return string |
||
| 105 | */ |
||
| 106 | public function getSearchString() |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return bool |
||
| 113 | */ |
||
| 114 | public function inPie() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | public function inPedigree() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @return bool |
||
| 129 | */ |
||
| 130 | public function inList() |
||
| 134 | |||
| 135 | public function getId() |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param $setting |
||
| 142 | * |
||
| 143 | * @return mixed |
||
| 144 | */ |
||
| 145 | public function getSetting($setting) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @param $fieldnumber |
||
| 152 | * |
||
| 153 | * @return array |
||
| 154 | */ |
||
| 155 | View Code Duplication | public function lookupField($fieldnumber) |
|
| 167 | |||
| 168 | /** |
||
| 169 | * @return XoopsFormLabel |
||
| 170 | */ |
||
| 171 | public function viewField() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @return string |
||
| 180 | */ |
||
| 181 | public function showField() |
||
| 185 | |||
| 186 | /** |
||
| 187 | * @return mixed|string |
||
| 188 | */ |
||
| 189 | public function showValue() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | public function searchField() |
||
| 204 | } |
||
| 205 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.