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 | final class FeGenerator |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * Directorio de Cache para las template de Documentos. |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $dirCache; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Datos de la Compañia. |
||
| 35 | * |
||
| 36 | * @var Company |
||
| 37 | */ |
||
| 38 | private $company; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Genera un invoice (Factura o Boleta). |
||
| 42 | * |
||
| 43 | * @param Invoice $invoice |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | 2 | View Code Duplication | public function buildInvoice(Invoice $invoice) |
| 60 | |||
| 61 | /** |
||
| 62 | * Genera una Nota Electrónica(Credito o Debito). |
||
| 63 | * |
||
| 64 | * @param Note $note |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | 4 | public function buildNote(Note $note) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * Genera una Resumen Diario de Boletas. |
||
| 86 | * |
||
| 87 | * @param Summary $summary |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | 2 | View Code Duplication | public function buildSummary(Summary $summary) |
| 104 | |||
| 105 | /** |
||
| 106 | * Genera una comunicacion de Baja. |
||
| 107 | * |
||
| 108 | * @param Voided $voided |
||
| 109 | * @return string |
||
| 110 | */ |
||
| 111 | 2 | View Code Duplication | public function buildVoided(Voided $voided) |
| 125 | |||
| 126 | /** |
||
| 127 | * @param string $dirCache |
||
| 128 | * @return FeGenerator |
||
| 129 | */ |
||
| 130 | 10 | public function setDirCache($dirCache) |
|
| 135 | |||
| 136 | /** |
||
| 137 | * @param Company $company |
||
| 138 | * @return FeGenerator |
||
| 139 | */ |
||
| 140 | 10 | public function setCompany($company) |
|
| 145 | |||
| 146 | 10 | private function getRender() |
|
| 155 | |||
| 156 | 10 | private function validate($entity) |
|
| 164 | } |
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.