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 |
||
| 18 | class BaseSale |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @Assert\NotBlank() |
||
| 22 | * @Assert\Length(max="2") |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $tipoDoc; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @Assert\NotBlank() |
||
| 29 | * @Assert\Length(max="4") |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $serie; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @Assert\NotBlank() |
||
| 36 | * @Assert\Length(max="8") |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $correlativo; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @Assert\NotBlank() |
||
| 43 | * @Assert\Date() |
||
| 44 | * @var \DateTime |
||
| 45 | */ |
||
| 46 | protected $fechaEmision; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @Assert\NotBlank() |
||
| 50 | * @Assert\Valid() |
||
| 51 | * @var Company |
||
| 52 | */ |
||
| 53 | protected $company; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @Assert\NotBlank() |
||
| 57 | * @Assert\Valid() |
||
| 58 | * @var Client |
||
| 59 | */ |
||
| 60 | protected $client; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @Assert\NotBlank() |
||
| 64 | * @Assert\Length(max="3") |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | protected $tipoMoneda; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var float |
||
| 71 | */ |
||
| 72 | protected $sumOtrosCargos; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @Assert\NotBlank() |
||
| 76 | * @Assert\Type("numeric") |
||
| 77 | * @var float |
||
| 78 | */ |
||
| 79 | protected $mtoOperGravadas; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @Assert\NotBlank() |
||
| 83 | * @Assert\Type("numeric") |
||
| 84 | * @var float |
||
| 85 | */ |
||
| 86 | protected $mtoOperInafectas; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @Assert\NotBlank() |
||
| 90 | * @Assert\Type("numeric") |
||
| 91 | * @var float |
||
| 92 | */ |
||
| 93 | protected $mtoOperExoneradas; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @var float |
||
| 97 | */ |
||
| 98 | protected $mtoIGV; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var float |
||
| 102 | */ |
||
| 103 | protected $mtoISC; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var float |
||
| 107 | */ |
||
| 108 | protected $mtoOtrosTributos; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Importe total de la venta, cesión en uso o del servicio prestado. |
||
| 112 | * |
||
| 113 | * @Assert\NotBlank() |
||
| 114 | * @Assert\Type("numeric") |
||
| 115 | * @var float |
||
| 116 | */ |
||
| 117 | protected $mtoImpVenta; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @Assert\Valid() |
||
| 121 | * @var SaleDetail[] |
||
| 122 | */ |
||
| 123 | protected $details; |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @Assert\Valid() |
||
| 127 | * @var Legend[] |
||
| 128 | */ |
||
| 129 | protected $legends; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @Assert\Valid() |
||
| 133 | * @var Document[] |
||
| 134 | */ |
||
| 135 | protected $relDocs; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | 28 | public function getTipoDoc() |
|
| 144 | |||
| 145 | /** |
||
| 146 | * @param string $tipoDoc |
||
| 147 | * @return BaseSale |
||
| 148 | */ |
||
| 149 | 48 | public function setTipoDoc($tipoDoc) |
|
| 150 | { |
||
| 151 | 48 | $this->tipoDoc = $tipoDoc; |
|
| 152 | 48 | return $this; |
|
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @return string |
||
| 157 | */ |
||
| 158 | 28 | public function getSerie() |
|
| 162 | |||
| 163 | /** |
||
| 164 | * @param string $serie |
||
| 165 | * @return BaseSale |
||
| 166 | */ |
||
| 167 | 48 | public function setSerie($serie) |
|
| 168 | { |
||
| 169 | 48 | $this->serie = $serie; |
|
| 170 | 48 | return $this; |
|
| 171 | } |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | 28 | public function getCorrelativo() |
|
| 180 | |||
| 181 | /** |
||
| 182 | * @param string $correlativo |
||
| 183 | * @return BaseSale |
||
| 184 | */ |
||
| 185 | 48 | public function setCorrelativo($correlativo) |
|
| 186 | { |
||
| 187 | 48 | $this->correlativo = $correlativo; |
|
| 188 | 48 | return $this; |
|
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @return \DateTime |
||
| 193 | */ |
||
| 194 | 24 | public function getFechaEmision() |
|
| 198 | |||
| 199 | /** |
||
| 200 | * @param \DateTime $fechaEmision |
||
| 201 | * @return BaseSale |
||
| 202 | */ |
||
| 203 | 48 | public function setFechaEmision($fechaEmision) |
|
| 204 | { |
||
| 205 | 48 | $this->fechaEmision = $fechaEmision; |
|
| 206 | 48 | return $this; |
|
| 207 | } |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @return Client |
||
| 211 | */ |
||
| 212 | 24 | public function getClient() |
|
| 216 | |||
| 217 | /** |
||
| 218 | * @param Client $client |
||
| 219 | * @return BaseSale |
||
| 220 | */ |
||
| 221 | 48 | public function setClient($client) |
|
| 222 | { |
||
| 223 | 48 | $this->client = $client; |
|
| 224 | 48 | return $this; |
|
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return Company |
||
| 229 | */ |
||
| 230 | 28 | public function getCompany() |
|
| 234 | |||
| 235 | /** |
||
| 236 | * @param Company $company |
||
| 237 | * @return BaseSale |
||
| 238 | */ |
||
| 239 | 48 | public function setCompany($company) |
|
| 240 | { |
||
| 241 | 48 | $this->company = $company; |
|
| 242 | 48 | return $this; |
|
| 243 | } |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @return mixed |
||
| 247 | */ |
||
| 248 | 24 | public function getTipoMoneda() |
|
| 252 | |||
| 253 | /** |
||
| 254 | * @param mixed $tipoMoneda |
||
| 255 | * @return BaseSale |
||
| 256 | */ |
||
| 257 | 48 | public function setTipoMoneda($tipoMoneda) |
|
| 258 | { |
||
| 259 | 48 | $this->tipoMoneda = $tipoMoneda; |
|
| 260 | 48 | return $this; |
|
| 261 | } |
||
| 262 | |||
| 263 | /** |
||
| 264 | * @return mixed |
||
| 265 | */ |
||
| 266 | 24 | public function getSumOtrosCargos() |
|
| 270 | |||
| 271 | /** |
||
| 272 | * @param mixed $sumOtrosCargos |
||
| 273 | * @return BaseSale |
||
| 274 | */ |
||
| 275 | 12 | public function setSumOtrosCargos($sumOtrosCargos) |
|
| 276 | { |
||
| 277 | 12 | $this->sumOtrosCargos = $sumOtrosCargos; |
|
| 278 | 12 | return $this; |
|
| 279 | } |
||
| 280 | |||
| 281 | /** |
||
| 282 | * @return mixed |
||
| 283 | */ |
||
| 284 | 24 | public function getMtoOperGravadas() |
|
| 288 | |||
| 289 | /** |
||
| 290 | * @param mixed $mtoOperGravadas |
||
| 291 | * @return BaseSale |
||
| 292 | */ |
||
| 293 | 48 | public function setMtoOperGravadas($mtoOperGravadas) |
|
| 294 | { |
||
| 295 | 48 | $this->mtoOperGravadas = $mtoOperGravadas; |
|
| 296 | 48 | return $this; |
|
| 297 | } |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @return mixed |
||
| 301 | */ |
||
| 302 | 24 | public function getMtoOperInafectas() |
|
| 306 | |||
| 307 | /** |
||
| 308 | * @param mixed $mtoOperInafectas |
||
| 309 | * @return BaseSale |
||
| 310 | */ |
||
| 311 | 48 | public function setMtoOperInafectas($mtoOperInafectas) |
|
| 312 | { |
||
| 313 | 48 | $this->mtoOperInafectas = $mtoOperInafectas; |
|
| 314 | 48 | return $this; |
|
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @return float |
||
| 319 | */ |
||
| 320 | 24 | public function getMtoOperExoneradas() |
|
| 324 | |||
| 325 | /** |
||
| 326 | * @param float $mtoOperExoneradas |
||
| 327 | * @return BaseSale |
||
| 328 | */ |
||
| 329 | 48 | public function setMtoOperExoneradas($mtoOperExoneradas) |
|
| 330 | { |
||
| 331 | 48 | $this->mtoOperExoneradas = $mtoOperExoneradas; |
|
| 332 | 48 | return $this; |
|
| 333 | } |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @return mixed |
||
| 337 | */ |
||
| 338 | 24 | public function getMtoIGV() |
|
| 342 | |||
| 343 | /** |
||
| 344 | * @param mixed $mtoIGV |
||
| 345 | * @return BaseSale |
||
| 346 | */ |
||
| 347 | 48 | public function setMtoIGV($mtoIGV) |
|
| 348 | { |
||
| 349 | 48 | $this->mtoIGV = $mtoIGV; |
|
| 350 | 48 | return $this; |
|
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * @return mixed |
||
| 355 | */ |
||
| 356 | 24 | public function getMtoISC() |
|
| 360 | |||
| 361 | /** |
||
| 362 | * @param mixed $mtoISC |
||
| 363 | * @return BaseSale |
||
| 364 | */ |
||
| 365 | 12 | public function setMtoISC($mtoISC) |
|
| 366 | { |
||
| 367 | 12 | $this->mtoISC = $mtoISC; |
|
| 368 | 12 | return $this; |
|
| 369 | } |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @return float |
||
| 373 | */ |
||
| 374 | 24 | public function getMtoOtrosTributos() |
|
| 378 | |||
| 379 | /** |
||
| 380 | * @param float $mtoOtrosTributos |
||
| 381 | * @return BaseSale |
||
| 382 | */ |
||
| 383 | 12 | public function setMtoOtrosTributos($mtoOtrosTributos) |
|
| 384 | { |
||
| 385 | 12 | $this->mtoOtrosTributos = $mtoOtrosTributos; |
|
| 386 | 12 | return $this; |
|
| 387 | } |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @return float |
||
| 391 | */ |
||
| 392 | 24 | public function getMtoImpVenta() |
|
| 396 | |||
| 397 | /** |
||
| 398 | * @param float $mtoImpVenta |
||
| 399 | * @return BaseSale |
||
| 400 | */ |
||
| 401 | 48 | public function setMtoImpVenta($mtoImpVenta) |
|
| 402 | { |
||
| 403 | 48 | $this->mtoImpVenta = $mtoImpVenta; |
|
| 404 | 48 | return $this; |
|
| 405 | } |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @return SaleDetail[] |
||
| 409 | */ |
||
| 410 | 24 | public function getDetails() |
|
| 414 | |||
| 415 | /** |
||
| 416 | * @param SaleDetail[] $details |
||
| 417 | * @return BaseSale |
||
| 418 | */ |
||
| 419 | 48 | public function setDetails($details) |
|
| 420 | { |
||
| 421 | 48 | $this->details = $details; |
|
| 422 | 48 | return $this; |
|
| 423 | } |
||
| 424 | |||
| 425 | /** |
||
| 426 | * @return Legend[] |
||
| 427 | */ |
||
| 428 | 24 | public function getLegends() |
|
| 432 | |||
| 433 | /** |
||
| 434 | * @param Legend[] $legends |
||
| 435 | * @return BaseSale |
||
| 436 | */ |
||
| 437 | 48 | public function setLegends($legends) |
|
| 438 | { |
||
| 439 | 48 | $this->legends = $legends; |
|
| 440 | 48 | return $this; |
|
| 441 | } |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @return Document[] |
||
| 445 | */ |
||
| 446 | 24 | public function getRelDocs() |
|
| 447 | { |
||
| 448 | 24 | return $this->relDocs; |
|
| 449 | } |
||
| 450 | |||
| 451 | /** |
||
| 452 | * @param Document[] $relDocs |
||
| 453 | * @return BaseSale |
||
| 454 | */ |
||
| 455 | 12 | public function setRelDocs($relDocs) |
|
| 460 | |||
| 461 | /** |
||
| 462 | * Get FileName without extension. |
||
| 463 | * |
||
| 464 | * @return string |
||
| 465 | */ |
||
| 466 | 22 | View Code Duplication | public function getFileName() |
| 477 | } |
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.