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 FeBuilder implements FeBuilderInteface |
||
| 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 | * FeBuilder constructor. |
||
| 42 | */ |
||
| 43 | 50 | public function __construct() |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Genera un invoice (Factura o Boleta). |
||
| 50 | * |
||
| 51 | * @param Invoice $invoice |
||
| 52 | * @throws ValidationException |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 10 | public function buildInvoice(Invoice $invoice) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Genera una Nota Electrónica(Credito o Debito). |
||
| 64 | * |
||
| 65 | * @param Note $note |
||
| 66 | * @throws ValidationException |
||
| 67 | * @return string |
||
| 68 | */ |
||
| 69 | 18 | public function buildNote(Note $note) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Genera una Resumen Diario de Boletas. |
||
| 81 | * |
||
| 82 | * @param Summary $summary |
||
| 83 | * @throws ValidationException |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | 10 | public function buildSummary(Summary $summary) |
|
| 92 | |||
| 93 | /** |
||
| 94 | * Genera una comunicacion de Baja. |
||
| 95 | * |
||
| 96 | * @param Voided $voided |
||
| 97 | * @throws ValidationException |
||
| 98 | * @return string |
||
| 99 | */ |
||
| 100 | 10 | public function buildVoided(Voided $voided) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * @param Company $company |
||
| 109 | * @return FeBuilder |
||
| 110 | */ |
||
| 111 | 50 | public function setCompany(Company $company) |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Set argumentos. |
||
| 119 | * |
||
| 120 | * @param array $params |
||
| 121 | * @throws \Exception |
||
| 122 | */ |
||
| 123 | 50 | View Code Duplication | public function setParameters($params) |
| 135 | |||
| 136 | /** |
||
| 137 | * Get Content XML from template. |
||
| 138 | * |
||
| 139 | * @param string $template |
||
| 140 | * @param object $doc |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | 30 | View Code Duplication | private function render($template, $doc) |
| 151 | |||
| 152 | 30 | View Code Duplication | private function getRender() |
| 161 | |||
| 162 | /** |
||
| 163 | * Validate Entity. |
||
| 164 | * |
||
| 165 | * @param object $entity |
||
| 166 | * @throws ValidationException |
||
| 167 | */ |
||
| 168 | 48 | View Code Duplication | private function validate($entity) |
| 179 | } |
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.