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 | View Code Duplication | class Voided |
|
|
|
|||
| 19 | { |
||
| 20 | use VoidedValidator; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @Assert\NotBlank() |
||
| 24 | * @Assert\Length(max="3") |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $correlativo; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @Assert\Date() |
||
| 31 | * @var \DateTime |
||
| 32 | */ |
||
| 33 | private $fecGeneracion; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @Assert\NotBlank() |
||
| 37 | * @Assert\Date() |
||
| 38 | * @var \DateTime |
||
| 39 | */ |
||
| 40 | private $fecComunicacion; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @Assert\Valid() |
||
| 44 | * @var VoidedDetail[] |
||
| 45 | */ |
||
| 46 | private $details; |
||
| 47 | |||
| 48 | 4 | public function __construct() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @return string |
||
| 55 | */ |
||
| 56 | 2 | public function getCorrelativo() |
|
| 60 | |||
| 61 | /** |
||
| 62 | * @param string $correlativo |
||
| 63 | * @return Voided |
||
| 64 | */ |
||
| 65 | 4 | public function setCorrelativo($correlativo) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * @return \DateTime |
||
| 73 | */ |
||
| 74 | 2 | public function getFecGeneracion() |
|
| 78 | |||
| 79 | /** |
||
| 80 | * @param \DateTime $fecGeneracion |
||
| 81 | * @return Voided |
||
| 82 | */ |
||
| 83 | 4 | public function setFecGeneracion($fecGeneracion) |
|
| 88 | |||
| 89 | /** |
||
| 90 | * @return \DateTime |
||
| 91 | */ |
||
| 92 | 2 | public function getFecComunicacion() |
|
| 96 | |||
| 97 | /** |
||
| 98 | * @param \DateTime $fecComunicacion |
||
| 99 | * @return Voided |
||
| 100 | */ |
||
| 101 | 4 | public function setFecComunicacion($fecComunicacion) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * @return VoidedDetail[] |
||
| 109 | */ |
||
| 110 | 2 | public function getDetails() |
|
| 114 | |||
| 115 | /** |
||
| 116 | * @param VoidedDetail[] $details |
||
| 117 | * @return Voided |
||
| 118 | */ |
||
| 119 | 4 | public function setDetails($details) |
|
| 124 | } |
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.