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 Summary |
|
|
|
|||
| 19 | { |
||
| 20 | use SummaryValidator; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @Assert\Length(max="3") |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | private $correlativo; |
||
| 27 | /** |
||
| 28 | * @Assert\Date() |
||
| 29 | * @var \DateTime |
||
| 30 | */ |
||
| 31 | private $fecGeneracion; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @Assert\NotBlank() |
||
| 35 | * @Assert\Date() |
||
| 36 | * @var \DateTime |
||
| 37 | */ |
||
| 38 | private $fecResumen; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @Assert\Valid() |
||
| 42 | * @var SummaryDetail[] |
||
| 43 | */ |
||
| 44 | private $details; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @return string |
||
| 48 | */ |
||
| 49 | 2 | public function getCorrelativo() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * @param string $correlativo |
||
| 56 | * @return Summary |
||
| 57 | */ |
||
| 58 | 4 | public function setCorrelativo($correlativo) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @return \DateTime |
||
| 66 | */ |
||
| 67 | 2 | public function getFecGeneracion() |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @param \DateTime $fecGeneracion |
||
| 74 | * @return Summary |
||
| 75 | */ |
||
| 76 | 4 | public function setFecGeneracion($fecGeneracion) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * @return \DateTime |
||
| 84 | */ |
||
| 85 | 2 | public function getFecResumen() |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @param \DateTime $fecResumen |
||
| 92 | * @return Summary |
||
| 93 | */ |
||
| 94 | 4 | public function setFecResumen($fecResumen) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * @return SummaryDetail[] |
||
| 102 | */ |
||
| 103 | 2 | public function getDetails() |
|
| 107 | |||
| 108 | /** |
||
| 109 | * @param SummaryDetail[] $details |
||
| 110 | * @return Summary |
||
| 111 | */ |
||
| 112 | 4 | public function setDetails($details) |
|
| 117 | } |
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.