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 |
||
| 25 | class CeBuilder implements CeBuilderInterface |
||
| 26 | { |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Directorio de Cache para las template de Documentos. |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | private $dirCache; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Datos de la Compañia. |
||
| 36 | * |
||
| 37 | * @var Company |
||
| 38 | */ |
||
| 39 | private $company; |
||
| 40 | |||
| 41 | |||
| 42 | /** |
||
| 43 | * CeBuilder constructor. |
||
| 44 | */ |
||
| 45 | 12 | public function __construct() |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Genera un comprobante de retencion. |
||
| 52 | * |
||
| 53 | * @param Retention $retention |
||
| 54 | * @throws ValidationException |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | 4 | public function buildRetention(Retention $retention) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Genera un comprobante de percepcion. |
||
| 66 | * |
||
| 67 | * @param Perception $perception |
||
| 68 | * @throws ValidationException |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | 4 | public function buildPerception(Perception $perception) |
|
| 77 | |||
| 78 | /** |
||
| 79 | * Genera una guia de remision. |
||
| 80 | * |
||
| 81 | * @param Despatch $despatch |
||
| 82 | * @throws ValidationException |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | 4 | public function buildDespatch(Despatch $despatch) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * Genera una resumen de reversiones. |
||
| 94 | * |
||
| 95 | * @param Reversion $reversion |
||
| 96 | * @throws ValidationException |
||
| 97 | * @return string |
||
| 98 | */ |
||
| 99 | public function buildReversion(Reversion $reversion) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @param Company $company |
||
| 108 | * @return CeBuilder |
||
| 109 | */ |
||
| 110 | 12 | public function setCompany(Company $company) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Set argumentos. |
||
| 118 | * |
||
| 119 | * @param array $params |
||
| 120 | * @throws \Exception |
||
| 121 | */ |
||
| 122 | View Code Duplication | public function setParameters($params) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Get Content XML from template. |
||
| 137 | * |
||
| 138 | * @param string $template |
||
| 139 | * @param object $doc |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | 6 | View Code Duplication | private function render($template, $doc) |
| 150 | |||
| 151 | 6 | View Code Duplication | private function getRender() |
| 160 | |||
| 161 | /** |
||
| 162 | * Validate Entity. |
||
| 163 | * |
||
| 164 | * @param object $entity |
||
| 165 | * @throws ValidationException |
||
| 166 | */ |
||
| 167 | 12 | View Code Duplication | private function validate($entity) |
| 178 | } |
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.