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 absences_Csv |
||
| 27 | { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $separator; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $sepdec; |
||
| 38 | |||
| 39 | |||
| 40 | protected function csvEncode($str) |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * output an array on raw values |
||
| 49 | * @param array $arr |
||
| 50 | * |
||
| 51 | */ |
||
| 52 | protected function outputArr(Array $arr) |
||
| 61 | |||
| 62 | |||
| 63 | /** |
||
| 64 | * |
||
| 65 | * @return boolean |
||
| 66 | */ |
||
| 67 | protected function isRowEmpty(Array $currentRow) |
||
| 81 | |||
| 82 | |||
| 83 | protected function encodeFloats(Array $currentRow) |
||
| 94 | |||
| 95 | |||
| 96 | /** |
||
| 97 | * @return string |
||
| 98 | */ |
||
| 99 | View Code Duplication | protected function getAgentDirValue(absences_Agent $agent, $fieldname) |
|
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | /** |
||
| 114 | * |
||
| 115 | * @param string $quantity_unit |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | View Code Duplication | protected function getUnit($quantity_unit) |
|
| 128 | |||
| 129 | |||
| 130 | protected function setHeaders($filename) |
||
| 136 | |||
| 137 | |||
| 138 | |||
| 139 | protected function date($strDate) { |
||
| 142 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.