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 |
||
| 19 | View Code Duplication | class Perception |
|
|
|
|||
| 20 | { |
||
| 21 | use PerceptionValidator; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Serie del Documento (ejem: P001) |
||
| 25 | * |
||
| 26 | * @Assert\NotBlank() |
||
| 27 | * @Assert\Length(max="4") |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $serie; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @Assert\NotBlank() |
||
| 34 | * @Assert\Length(max="8") |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $correlativo; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @Assert\Date() |
||
| 41 | * @var \DateTime |
||
| 42 | */ |
||
| 43 | private $fechaEmision; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @Assert\NotBlank() |
||
| 47 | * @Assert\Valid() |
||
| 48 | * @var Company |
||
| 49 | */ |
||
| 50 | private $company; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @Assert\NotBlank() |
||
| 54 | * @Assert\Valid() |
||
| 55 | * @var Client |
||
| 56 | */ |
||
| 57 | private $proveedor; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @Assert\NotBlank() |
||
| 61 | * @Assert\Length(min="2", max="2") |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | private $regimen; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @Assert\NotBlank() |
||
| 68 | * @var float |
||
| 69 | */ |
||
| 70 | private $tasa; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Importe total Percibido. |
||
| 74 | * |
||
| 75 | * @Assert\NotBlank() |
||
| 76 | * @var float |
||
| 77 | */ |
||
| 78 | private $impPercibido; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Importe total Cobrado. |
||
| 82 | * |
||
| 83 | * @Assert\NotBlank() |
||
| 84 | * @var float |
||
| 85 | */ |
||
| 86 | private $impCobrado; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @Assert\Length(max="250") |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | private $observacion; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Dato del Comprobante relacionado. |
||
| 96 | * |
||
| 97 | * @Assert\NotBlank() |
||
| 98 | * @Assert\Valid() |
||
| 99 | * @var PerceptionDetail[] |
||
| 100 | */ |
||
| 101 | private $details; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @return string |
||
| 105 | */ |
||
| 106 | 8 | public function getSerie() |
|
| 110 | |||
| 111 | /** |
||
| 112 | * @param string $serie |
||
| 113 | * @return Perception |
||
| 114 | */ |
||
| 115 | 14 | public function setSerie($serie) |
|
| 116 | { |
||
| 117 | 14 | $this->serie = $serie; |
|
| 118 | 14 | return $this; |
|
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @return string |
||
| 123 | */ |
||
| 124 | 8 | public function getCorrelativo() |
|
| 128 | |||
| 129 | /** |
||
| 130 | * @param string $correlativo |
||
| 131 | * @return Perception |
||
| 132 | */ |
||
| 133 | 14 | public function setCorrelativo($correlativo) |
|
| 134 | { |
||
| 135 | 14 | $this->correlativo = $correlativo; |
|
| 136 | 14 | return $this; |
|
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return \DateTime |
||
| 141 | */ |
||
| 142 | 6 | public function getFechaEmision() |
|
| 146 | |||
| 147 | /** |
||
| 148 | * @param \DateTime $fechaEmision |
||
| 149 | * @return Perception |
||
| 150 | */ |
||
| 151 | 14 | public function setFechaEmision($fechaEmision) |
|
| 152 | { |
||
| 153 | 14 | $this->fechaEmision = $fechaEmision; |
|
| 154 | 14 | return $this; |
|
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return Company |
||
| 159 | */ |
||
| 160 | 8 | public function getCompany() |
|
| 164 | |||
| 165 | /** |
||
| 166 | * @param Company $company |
||
| 167 | * @return Perception |
||
| 168 | */ |
||
| 169 | 14 | public function setCompany($company) |
|
| 170 | { |
||
| 171 | 14 | $this->company = $company; |
|
| 172 | 14 | return $this; |
|
| 173 | } |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return Client |
||
| 177 | */ |
||
| 178 | 6 | public function getProveedor() |
|
| 182 | |||
| 183 | /** |
||
| 184 | * @param Client $proveedor |
||
| 185 | * @return Perception |
||
| 186 | */ |
||
| 187 | 14 | public function setProveedor($proveedor) |
|
| 188 | { |
||
| 189 | 14 | $this->proveedor = $proveedor; |
|
| 190 | 14 | return $this; |
|
| 191 | } |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return string |
||
| 195 | */ |
||
| 196 | 6 | public function getRegimen() |
|
| 200 | |||
| 201 | /** |
||
| 202 | * @param string $regimen |
||
| 203 | * @return Perception |
||
| 204 | */ |
||
| 205 | 14 | public function setRegimen($regimen) |
|
| 206 | { |
||
| 207 | 14 | $this->regimen = $regimen; |
|
| 208 | 14 | return $this; |
|
| 209 | } |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @return float |
||
| 213 | */ |
||
| 214 | 6 | public function getTasa() |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @param float $tasa |
||
| 221 | * @return Perception |
||
| 222 | */ |
||
| 223 | 14 | public function setTasa($tasa) |
|
| 224 | { |
||
| 225 | 14 | $this->tasa = $tasa; |
|
| 226 | 14 | return $this; |
|
| 227 | } |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return float |
||
| 231 | */ |
||
| 232 | 6 | public function getImpPercibido() |
|
| 236 | |||
| 237 | /** |
||
| 238 | * @param float $impPercibido |
||
| 239 | * @return Perception |
||
| 240 | */ |
||
| 241 | 14 | public function setImpPercibido($impPercibido) |
|
| 242 | { |
||
| 243 | 14 | $this->impPercibido = $impPercibido; |
|
| 244 | 14 | return $this; |
|
| 245 | } |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return float |
||
| 249 | */ |
||
| 250 | 6 | public function getImpCobrado() |
|
| 254 | |||
| 255 | /** |
||
| 256 | * @param float $impCobrado |
||
| 257 | * @return Perception |
||
| 258 | */ |
||
| 259 | 14 | public function setImpCobrado($impCobrado) |
|
| 260 | { |
||
| 261 | 14 | $this->impCobrado = $impCobrado; |
|
| 262 | 14 | return $this; |
|
| 263 | } |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @return string |
||
| 267 | */ |
||
| 268 | 6 | public function getObservacion() |
|
| 272 | |||
| 273 | /** |
||
| 274 | * @param string $observacion |
||
| 275 | * @return Perception |
||
| 276 | */ |
||
| 277 | 14 | public function setObservacion($observacion) |
|
| 278 | { |
||
| 279 | 14 | $this->observacion = $observacion; |
|
| 280 | 14 | return $this; |
|
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @return PerceptionDetail[] |
||
| 285 | */ |
||
| 286 | 6 | public function getDetails() |
|
| 290 | |||
| 291 | /** |
||
| 292 | * @param PerceptionDetail[] $details |
||
| 293 | * @return Perception |
||
| 294 | */ |
||
| 295 | 14 | public function setDetails($details) |
|
| 300 | |||
| 301 | /** |
||
| 302 | * Get FileName without extension. |
||
| 303 | * |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | 6 | public function getFileName() |
|
| 317 | } |
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.