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 |
||
| 27 | class MBM5 extends Sensors |
||
|
|
|||
| 28 | { |
||
| 29 | /** |
||
| 30 | * array with the names of the labels |
||
| 31 | * |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $_buf_label = array(); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * array withe the values |
||
| 38 | * |
||
| 39 | * @var array |
||
| 40 | */ |
||
| 41 | private $_buf_value = array(); |
||
| 42 | |||
| 43 | /** |
||
| 44 | * read the MBM5.csv file and fill the private arrays |
||
| 45 | */ |
||
| 46 | public function __construct() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * get temperature information |
||
| 61 | * |
||
| 62 | * @return void |
||
| 63 | */ |
||
| 64 | View Code Duplication | private function _temperature() |
|
| 78 | |||
| 79 | /** |
||
| 80 | * get fan information |
||
| 81 | * |
||
| 82 | * @return void |
||
| 83 | */ |
||
| 84 | View Code Duplication | private function _fans() |
|
| 98 | |||
| 99 | /** |
||
| 100 | * get voltage information |
||
| 101 | * |
||
| 102 | * @return void |
||
| 103 | */ |
||
| 104 | View Code Duplication | private function _voltage() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * get the information |
||
| 120 | * |
||
| 121 | * @see PSI_Interface_Sensor::build() |
||
| 122 | * |
||
| 123 | * @return Void |
||
| 124 | */ |
||
| 125 | public function build() |
||
| 131 | } |
||
| 132 |
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.