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 |
||
| 20 | class XoopstubeLists |
||
|
|
|||
| 21 | { |
||
| 22 | public $value; |
||
| 23 | public $selected; |
||
| 24 | public $path = 'uploads'; |
||
| 25 | public $size; |
||
| 26 | public $emptyselect; |
||
| 27 | public $type; |
||
| 28 | public $prefix; |
||
| 29 | public $suffix; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $path |
||
| 33 | * @param null $value |
||
| 34 | * @param string $selected |
||
| 35 | * @param int $size |
||
| 36 | * @param int $emptyselect |
||
| 37 | * @param int $type |
||
| 38 | * @param string $prefix |
||
| 39 | * @param string $suffix |
||
| 40 | */ |
||
| 41 | public function __construct( |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @param $this_array |
||
| 61 | * |
||
| 62 | * @return string |
||
| 63 | */ |
||
| 64 | View Code Duplication | public function &getarray($this_array) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * Private to be called by other parts of the class |
||
| 85 | * |
||
| 86 | * @param $dirname |
||
| 87 | * |
||
| 88 | * @return array |
||
| 89 | */ |
||
| 90 | public function &getDirListAsArray($dirname) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @param $dirname |
||
| 111 | * @param string $type |
||
| 112 | * @param string $prefix |
||
| 113 | * @param int $noselection |
||
| 114 | * |
||
| 115 | * @return array |
||
| 116 | */ |
||
| 117 | public static function &getListTypeAsArray($dirname, $type = '', $prefix = '', $noselection = 1) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * @return null |
||
| 171 | */ |
||
| 172 | public function value() |
||
| 176 | |||
| 177 | public function isSelected() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | public function paths() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return int |
||
| 192 | */ |
||
| 193 | public function size() |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return int |
||
| 200 | */ |
||
| 201 | public function isEmptySelect() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @return int |
||
| 208 | */ |
||
| 209 | public function getType() |
||
| 213 | |||
| 214 | public function getPrefix() |
||
| 218 | |||
| 219 | public function getSuffix() |
||
| 223 | } |
||
| 224 |
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.