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 |
||
| 17 | View Code Duplication | class RetentionDetail |
|
|
|
|||
| 18 | { |
||
| 19 | use RetentionDetailValidator; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Tipo de documento Relacionado. |
||
| 23 | * |
||
| 24 | * @Assert\NotBlank() |
||
| 25 | * @Assert\Length(max="2") |
||
| 26 | * @var string |
||
| 27 | */ |
||
| 28 | private $tipoDoc; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Numero del documento relacionado (Serie-Correlativo). |
||
| 32 | * |
||
| 33 | * @Assert\NotBlank() |
||
| 34 | * @Assert\Length(max="13") |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $numDoc; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Fecha de Emision del documento relacionado. |
||
| 41 | * |
||
| 42 | * @Assert\NotBlank() |
||
| 43 | * @Assert\Date() |
||
| 44 | * @var \DateTime |
||
| 45 | */ |
||
| 46 | private $fechaEmision; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Importe total documento Relacionado. |
||
| 50 | * |
||
| 51 | * @Assert\NotBlank() |
||
| 52 | * @var float |
||
| 53 | */ |
||
| 54 | private $impTotal; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Moneda del docoumento relacionado. |
||
| 58 | * |
||
| 59 | * @Assert\NotBlank() |
||
| 60 | * @Assert\Length(min="3", max="3") |
||
| 61 | * @var string |
||
| 62 | */ |
||
| 63 | private $moneda; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Datos del Pago. |
||
| 67 | * |
||
| 68 | * @Assert\NotBlank() |
||
| 69 | * @Assert\Valid() |
||
| 70 | * @var Payment[] |
||
| 71 | */ |
||
| 72 | private $pagos; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Fecha de Retención. |
||
| 76 | * |
||
| 77 | * @Assert\NotBlank() |
||
| 78 | * @Assert\Date() |
||
| 79 | * @var \DateTime |
||
| 80 | */ |
||
| 81 | private $fechaRetencion; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Importe retenido. |
||
| 85 | * |
||
| 86 | * @Assert\NotBlank() |
||
| 87 | * @var float |
||
| 88 | */ |
||
| 89 | private $impRetenido; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Importe total a pagar (neto). |
||
| 93 | * |
||
| 94 | * @Assert\NotBlank() |
||
| 95 | * @var float |
||
| 96 | */ |
||
| 97 | private $impPagar; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @Assert\Valid() |
||
| 101 | * @var Exchange |
||
| 102 | */ |
||
| 103 | private $tipoCambio; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return string |
||
| 107 | */ |
||
| 108 | public function getTipoDoc() |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param string $tipoDoc |
||
| 115 | * @return RetentionDetail |
||
| 116 | */ |
||
| 117 | public function setTipoDoc($tipoDoc) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @return string |
||
| 125 | */ |
||
| 126 | public function getNumDoc() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param string $numDoc |
||
| 133 | * @return RetentionDetail |
||
| 134 | */ |
||
| 135 | public function setNumDoc($numDoc) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return \DateTime |
||
| 143 | */ |
||
| 144 | public function getFechaEmision() |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param \DateTime $fechaEmision |
||
| 151 | * @return RetentionDetail |
||
| 152 | */ |
||
| 153 | public function setFechaEmision($fechaEmision) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @return float |
||
| 161 | */ |
||
| 162 | public function getImpTotal() |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @param float $impTotal |
||
| 169 | * @return RetentionDetail |
||
| 170 | */ |
||
| 171 | public function setImpTotal($impTotal) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @return string |
||
| 179 | */ |
||
| 180 | public function getMoneda() |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @param string $moneda |
||
| 187 | * @return RetentionDetail |
||
| 188 | */ |
||
| 189 | public function setMoneda($moneda) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return Payment[] |
||
| 197 | */ |
||
| 198 | public function getPagos() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @param Payment[] $pagos |
||
| 205 | * @return RetentionDetail |
||
| 206 | */ |
||
| 207 | public function setPagos($pagos) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @return \DateTime |
||
| 215 | */ |
||
| 216 | public function getFechaRetencion() |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @param \DateTime $fechaRetencion |
||
| 223 | * @return RetentionDetail |
||
| 224 | */ |
||
| 225 | public function setFechaRetencion($fechaRetencion) |
||
| 230 | |||
| 231 | /** |
||
| 232 | * @return float |
||
| 233 | */ |
||
| 234 | public function getImpRetenido() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @param float $impRetenido |
||
| 241 | * @return RetentionDetail |
||
| 242 | */ |
||
| 243 | public function setImpRetenido($impRetenido) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @return float |
||
| 251 | */ |
||
| 252 | public function getImpPagar() |
||
| 256 | |||
| 257 | /** |
||
| 258 | * @param float $impPagar |
||
| 259 | * @return RetentionDetail |
||
| 260 | */ |
||
| 261 | public function setImpPagar($impPagar) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return Exchange |
||
| 269 | */ |
||
| 270 | public function getTipoCambio() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @param Exchange $tipoCambio |
||
| 277 | * @return RetentionDetail |
||
| 278 | */ |
||
| 279 | public function setTipoCambio($tipoCambio) |
||
| 284 | } |
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.