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 |
||
| 26 | class OHM extends Sensors |
||
|
|
|||
| 27 | { |
||
| 28 | /** |
||
| 29 | * holds the COM object that we pull all the WMI data from |
||
| 30 | * |
||
| 31 | * @var Object |
||
| 32 | */ |
||
| 33 | private $_buf = array(); |
||
| 34 | |||
| 35 | /** |
||
| 36 | * fill the private content var |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function __construct() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * get temperature information |
||
| 65 | * |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | View Code Duplication | private function _temperature() |
|
| 79 | |||
| 80 | /** |
||
| 81 | * get voltage information |
||
| 82 | * |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | View Code Duplication | private function _voltage() |
|
| 96 | |||
| 97 | /** |
||
| 98 | * get fan information |
||
| 99 | * |
||
| 100 | * @return void |
||
| 101 | */ |
||
| 102 | View Code Duplication | private function _fans() |
|
| 113 | |||
| 114 | /** |
||
| 115 | * get power information |
||
| 116 | * |
||
| 117 | * @return void |
||
| 118 | */ |
||
| 119 | View Code Duplication | private function _power() |
|
| 130 | |||
| 131 | /** |
||
| 132 | * get the information |
||
| 133 | * |
||
| 134 | * @see PSI_Interface_Sensor::build() |
||
| 135 | * |
||
| 136 | * @return Void |
||
| 137 | */ |
||
| 138 | public function build() |
||
| 145 | } |
||
| 146 |
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.