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 |
||
| 21 | class Despatch |
||
| 22 | { |
||
| 23 | use DespatchValidator; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @Assert\NotBlank() |
||
| 27 | * @Assert\Length(max="2") |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $tipoDoc; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Serie del Documento (ejem: T001) |
||
| 34 | * |
||
| 35 | * @Assert\NotBlank() |
||
| 36 | * @Assert\Length(max="4") |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | private $serie; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @Assert\NotBlank() |
||
| 43 | * @Assert\Length(max="8") |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $correlativo; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @Assert\Length(max="250") |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $observacion; |
||
| 53 | /** |
||
| 54 | * @Assert\Date() |
||
| 55 | * @var \DateTime |
||
| 56 | */ |
||
| 57 | private $fechaEmision; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @Assert\NotBlank() |
||
| 61 | * @Assert\Valid() |
||
| 62 | * @var Company |
||
| 63 | */ |
||
| 64 | private $company; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @Assert\NotBlank() |
||
| 68 | * @Assert\Valid() |
||
| 69 | * @var Client |
||
| 70 | */ |
||
| 71 | private $destinatario; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Datos del Establecimiento del tercero (cuando se ingrese) |
||
| 75 | * |
||
| 76 | * @Assert\Valid() |
||
| 77 | * @var Client |
||
| 78 | */ |
||
| 79 | private $tercero; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @Assert\NotBlank() |
||
| 83 | * @Assert\Valid() |
||
| 84 | * @var Shipment |
||
| 85 | */ |
||
| 86 | private $envio; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @Assert\Valid() |
||
| 90 | * @var Document |
||
| 91 | */ |
||
| 92 | private $docBaja; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @Assert\Valid() |
||
| 96 | * @var Document |
||
| 97 | */ |
||
| 98 | private $relDoc; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @Assert\NotBlank() |
||
| 102 | * @Assert\Valid() |
||
| 103 | * @var DespatchDetail[] |
||
| 104 | */ |
||
| 105 | private $details; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | 6 | public function getTipoDoc() |
|
| 114 | |||
| 115 | /** |
||
| 116 | * @param string $tipoDoc |
||
| 117 | * @return Despatch |
||
| 118 | */ |
||
| 119 | 12 | public function setTipoDoc($tipoDoc) |
|
| 120 | { |
||
| 121 | 12 | $this->tipoDoc = $tipoDoc; |
|
| 122 | 12 | return $this; |
|
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return string |
||
| 127 | */ |
||
| 128 | 6 | public function getSerie() |
|
| 132 | |||
| 133 | /** |
||
| 134 | * @param string $serie |
||
| 135 | * @return Despatch |
||
| 136 | */ |
||
| 137 | 12 | public function setSerie($serie) |
|
| 138 | { |
||
| 139 | 12 | $this->serie = $serie; |
|
| 140 | 12 | return $this; |
|
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @return string |
||
| 145 | */ |
||
| 146 | 6 | public function getCorrelativo() |
|
| 150 | |||
| 151 | /** |
||
| 152 | * @param string $correlativo |
||
| 153 | * @return Despatch |
||
| 154 | */ |
||
| 155 | 12 | public function setCorrelativo($correlativo) |
|
| 156 | { |
||
| 157 | 12 | $this->correlativo = $correlativo; |
|
| 158 | 12 | return $this; |
|
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * @return string |
||
| 163 | */ |
||
| 164 | 4 | public function getObservacion() |
|
| 168 | |||
| 169 | /** |
||
| 170 | * @param string $observacion |
||
| 171 | * @return Despatch |
||
| 172 | */ |
||
| 173 | 12 | public function setObservacion($observacion) |
|
| 174 | { |
||
| 175 | 12 | $this->observacion = $observacion; |
|
| 176 | 12 | return $this; |
|
| 177 | } |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return \DateTime |
||
| 181 | */ |
||
| 182 | 4 | public function getFechaEmision() |
|
| 186 | |||
| 187 | /** |
||
| 188 | * @param \DateTime $fechaEmision |
||
| 189 | * @return Despatch |
||
| 190 | */ |
||
| 191 | 12 | public function setFechaEmision($fechaEmision) |
|
| 192 | { |
||
| 193 | 12 | $this->fechaEmision = $fechaEmision; |
|
| 194 | 12 | return $this; |
|
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return Company |
||
| 199 | */ |
||
| 200 | 6 | public function getCompany() |
|
| 204 | |||
| 205 | /** |
||
| 206 | * @param Company $company |
||
| 207 | * @return Despatch |
||
| 208 | */ |
||
| 209 | 12 | public function setCompany($company) |
|
| 210 | { |
||
| 211 | 12 | $this->company = $company; |
|
| 212 | 12 | return $this; |
|
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return Client |
||
| 217 | */ |
||
| 218 | 4 | public function getDestinatario() |
|
| 222 | |||
| 223 | /** |
||
| 224 | * @param Client $destinatario |
||
| 225 | * @return Despatch |
||
| 226 | */ |
||
| 227 | 12 | public function setDestinatario($destinatario) |
|
| 228 | { |
||
| 229 | 12 | $this->destinatario = $destinatario; |
|
| 230 | 12 | return $this; |
|
| 231 | } |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return Client |
||
| 235 | */ |
||
| 236 | 4 | public function getTercero() |
|
| 240 | |||
| 241 | /** |
||
| 242 | * @param Client $tercero |
||
| 243 | * @return Despatch |
||
| 244 | */ |
||
| 245 | 12 | public function setTercero($tercero) |
|
| 246 | { |
||
| 247 | 12 | $this->tercero = $tercero; |
|
| 248 | 12 | return $this; |
|
| 249 | } |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return Shipment |
||
| 253 | */ |
||
| 254 | 4 | public function getEnvio() |
|
| 258 | |||
| 259 | /** |
||
| 260 | * @param Shipment $envio |
||
| 261 | * @return Despatch |
||
| 262 | */ |
||
| 263 | 12 | public function setEnvio($envio) |
|
| 264 | { |
||
| 265 | 12 | $this->envio = $envio; |
|
| 266 | 12 | return $this; |
|
| 267 | } |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @return Document |
||
| 271 | */ |
||
| 272 | 4 | public function getDocBaja() |
|
| 276 | |||
| 277 | /** |
||
| 278 | * @param Document $docBaja |
||
| 279 | * @return Despatch |
||
| 280 | */ |
||
| 281 | 12 | public function setDocBaja($docBaja) |
|
| 282 | { |
||
| 283 | 12 | $this->docBaja = $docBaja; |
|
| 284 | 12 | return $this; |
|
| 285 | } |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return Document |
||
| 289 | */ |
||
| 290 | 4 | public function getRelDoc() |
|
| 294 | |||
| 295 | /** |
||
| 296 | * @param Document $relDoc |
||
| 297 | * @return Despatch |
||
| 298 | */ |
||
| 299 | 12 | public function setRelDoc($relDoc) |
|
| 300 | { |
||
| 301 | 12 | $this->relDoc = $relDoc; |
|
| 302 | 12 | return $this; |
|
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @return DespatchDetail[] |
||
| 307 | */ |
||
| 308 | 4 | public function getDetails() |
|
| 312 | |||
| 313 | /** |
||
| 314 | * @param DespatchDetail[] $details |
||
| 315 | * @return Despatch |
||
| 316 | */ |
||
| 317 | 12 | public function setDetails($details) |
|
| 322 | |||
| 323 | /** |
||
| 324 | * Get FileName without extension. |
||
| 325 | * |
||
| 326 | * @return string |
||
| 327 | */ |
||
| 328 | 4 | View Code Duplication | public function getFileName() |
| 339 | } |
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.