Complex classes like Parte often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Parte, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class Parte |
||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @ORM\Id |
||
| 39 | * @ORM\Column(type="integer") |
||
| 40 | * @ORM\GeneratedValue |
||
| 41 | */ |
||
| 42 | protected $id; |
||
| 43 | /** |
||
| 44 | * @ORM\ManyToOne(targetEntity="Usuario", inversedBy="partes") |
||
| 45 | * @ORM\JoinColumn(nullable=false) |
||
| 46 | * @var Usuario |
||
| 47 | * |
||
| 48 | * @Assert\NotBlank() |
||
| 49 | */ |
||
| 50 | protected $usuario; |
||
| 51 | /** |
||
| 52 | * @ORM\ManyToOne(targetEntity="Alumno", inversedBy="partes") |
||
| 53 | * @ORM\JoinColumn(nullable=false) |
||
| 54 | * @var Alumno |
||
| 55 | */ |
||
| 56 | protected $alumno; |
||
| 57 | /** |
||
| 58 | * @ORM\Column(type="text", nullable=false) |
||
| 59 | * @var string |
||
| 60 | * |
||
| 61 | * @Assert\NotBlank |
||
| 62 | * @Assert\Length(min="10", minMessage="parte.anotacion.min_length") |
||
| 63 | */ |
||
| 64 | protected $anotacion; |
||
| 65 | /** |
||
| 66 | * @ORM\Column(type="text", nullable=true) |
||
| 67 | * @var string |
||
| 68 | * |
||
| 69 | * @Assert\NotBlank(groups={"expulsion"}, message="parte.actividades.expulsion") |
||
| 70 | */ |
||
| 71 | protected $actividades; |
||
| 72 | /** |
||
| 73 | * @ORM\Column(type="datetime", nullable=false) |
||
| 74 | * @var \DateTime |
||
| 75 | */ |
||
| 76 | protected $fechaCreacion; |
||
| 77 | /** |
||
| 78 | * @ORM\Column(type="datetime", nullable=false) |
||
| 79 | * @var \DateTime |
||
| 80 | * |
||
| 81 | * @Assert\NotBlank(groups={"nuevo"}, message="parte.fecha_suceso.not_blank") |
||
| 82 | * @AssertDateRange(max="now +10 minute", maxMessage="parte.fecha_suceso.max") |
||
| 83 | */ |
||
| 84 | protected $fechaSuceso; |
||
| 85 | /** |
||
| 86 | * @ORM\ManyToOne(targetEntity="TramoParte") |
||
| 87 | * @ORM\JoinColumn(nullable=false) |
||
| 88 | * @var TramoParte |
||
| 89 | * |
||
| 90 | * @Assert\NotBlank(groups={"nuevo"}, message="parte.tramo.not_blank") |
||
| 91 | */ |
||
| 92 | protected $tramo; |
||
| 93 | /** |
||
| 94 | * @ORM\Column(type="datetime", nullable=true) |
||
| 95 | * @var \DateTime |
||
| 96 | */ |
||
| 97 | protected $fechaAviso; |
||
| 98 | /** |
||
| 99 | * @ORM\Column(type="datetime", nullable=true) |
||
| 100 | * @var \DateTime |
||
| 101 | */ |
||
| 102 | protected $fechaRecordatorio; |
||
| 103 | /** |
||
| 104 | * @ORM\Column(type="boolean", nullable=false) |
||
| 105 | * @var boolean |
||
| 106 | */ |
||
| 107 | protected $prescrito; |
||
| 108 | /** |
||
| 109 | * @ORM\Column(type="boolean", nullable=false) |
||
| 110 | * @var boolean |
||
| 111 | */ |
||
| 112 | protected $prioritario; |
||
| 113 | /** |
||
| 114 | * @ORM\Column(type="boolean", nullable=false) |
||
| 115 | * @var boolean |
||
| 116 | */ |
||
| 117 | protected $hayExpulsion; |
||
| 118 | /** |
||
| 119 | * @ORM\Column(type="boolean", nullable=true) |
||
| 120 | * @var boolean |
||
| 121 | */ |
||
| 122 | protected $actividadesRealizadas; |
||
| 123 | /** |
||
| 124 | * @ORM\ManyToMany(targetEntity="TipoConducta") |
||
| 125 | * @var Collection |
||
| 126 | * |
||
| 127 | * @Assert\Count(min="1", minMessage="parte.conductas.min") |
||
| 128 | */ |
||
| 129 | protected $conductas = null; |
||
| 130 | /** |
||
| 131 | * @ORM\ManyToOne(targetEntity="Sancion", inversedBy="partes") |
||
| 132 | * @var Sancion |
||
| 133 | */ |
||
| 134 | protected $sancion; |
||
| 135 | /** |
||
| 136 | * @ORM\OneToMany(targetEntity="ObservacionParte", mappedBy="parte") |
||
| 137 | * @var Collection |
||
| 138 | */ |
||
| 139 | protected $observaciones = null; |
||
| 140 | /** |
||
| 141 | * @ORM\OneToMany(targetEntity="AvisoParte", mappedBy="parte") |
||
| 142 | * @var Collection |
||
| 143 | */ |
||
| 144 | protected $avisos = null; |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Constructor |
||
| 148 | */ |
||
| 149 | public function __construct() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Get id |
||
| 158 | * |
||
| 159 | * @return integer |
||
| 160 | */ |
||
| 161 | public function getId() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Set anotacion |
||
| 168 | * |
||
| 169 | * @param string $anotacion |
||
| 170 | * @return Parte |
||
| 171 | */ |
||
| 172 | public function setAnotacion($anotacion) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Get anotacion |
||
| 181 | * |
||
| 182 | * @return string |
||
| 183 | */ |
||
| 184 | public function getAnotacion() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Set actividades |
||
| 191 | * |
||
| 192 | * @param string $actividades |
||
| 193 | * @return Parte |
||
| 194 | */ |
||
| 195 | public function setActividades($actividades) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get actividades |
||
| 204 | * |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | public function getActividades() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Set fechaCreacion |
||
| 214 | * |
||
| 215 | * @param \DateTime $fechaCreacion |
||
| 216 | * @return Parte |
||
| 217 | */ |
||
| 218 | public function setFechaCreacion($fechaCreacion) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Get fechaCreacion |
||
| 227 | * |
||
| 228 | * @return \DateTime |
||
| 229 | */ |
||
| 230 | public function getFechaCreacion() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Set fechaSuceso |
||
| 237 | * |
||
| 238 | * @param \DateTime $fechaSuceso |
||
| 239 | * @return Parte |
||
| 240 | */ |
||
| 241 | public function setFechaSuceso($fechaSuceso) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Get fechaSuceso |
||
| 250 | * |
||
| 251 | * @return \DateTime |
||
| 252 | */ |
||
| 253 | public function getFechaSuceso() |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Set fechaAviso |
||
| 260 | * |
||
| 261 | * @param \DateTime $fechaAviso |
||
| 262 | * @return Parte |
||
| 263 | */ |
||
| 264 | public function setFechaAviso($fechaAviso) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Get fechaAviso |
||
| 273 | * |
||
| 274 | * @return \DateTime |
||
| 275 | */ |
||
| 276 | public function getFechaAviso() |
||
| 280 | |||
| 281 | /** |
||
| 282 | * Set usuario |
||
| 283 | * |
||
| 284 | * @param Usuario $usuario |
||
| 285 | * @return Parte |
||
| 286 | */ |
||
| 287 | public function setUsuario(Usuario $usuario = null) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Get usuario |
||
| 296 | * |
||
| 297 | * @return Usuario |
||
| 298 | */ |
||
| 299 | public function getUsuario() |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Set alumno |
||
| 306 | * |
||
| 307 | * @param Alumno $alumno |
||
| 308 | * @return Parte |
||
| 309 | */ |
||
| 310 | public function setAlumno(Alumno $alumno = null) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Get alumno |
||
| 319 | * |
||
| 320 | * @return Alumno |
||
| 321 | */ |
||
| 322 | public function getAlumno() |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Set sancion |
||
| 329 | * |
||
| 330 | * @param Sancion $sancion |
||
| 331 | * @return Parte |
||
| 332 | */ |
||
| 333 | public function setSancion(Sancion $sancion = null) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Get sancion |
||
| 342 | * |
||
| 343 | * @return Sancion |
||
| 344 | */ |
||
| 345 | public function getSancion() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * Add observaciones |
||
| 352 | * |
||
| 353 | * @param ObservacionParte $observaciones |
||
| 354 | * @return Parte |
||
| 355 | */ |
||
| 356 | public function addObservacion(ObservacionParte $observaciones) |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Remove observaciones |
||
| 365 | * |
||
| 366 | * @param ObservacionParte $observaciones |
||
| 367 | */ |
||
| 368 | public function removeObservacion(ObservacionParte $observaciones) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * Get observaciones |
||
| 375 | * |
||
| 376 | * @return Collection |
||
| 377 | */ |
||
| 378 | public function getObservaciones() |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Add avisos |
||
| 385 | * |
||
| 386 | * @param AvisoParte $avisos |
||
| 387 | * @return Parte |
||
| 388 | */ |
||
| 389 | public function addAviso(AvisoParte $avisos) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Remove avisos |
||
| 398 | * |
||
| 399 | * @param AvisoParte $avisos |
||
| 400 | */ |
||
| 401 | public function removeAviso(AvisoParte $avisos) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Get avisos |
||
| 408 | * |
||
| 409 | * @return Collection |
||
| 410 | */ |
||
| 411 | public function getAvisos() |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Set prescrito |
||
| 418 | * |
||
| 419 | * @param boolean $prescrito |
||
| 420 | * @return Parte |
||
| 421 | */ |
||
| 422 | public function setPrescrito($prescrito) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Get prescrito |
||
| 431 | * |
||
| 432 | * @return boolean |
||
| 433 | */ |
||
| 434 | public function getPrescrito() |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Set prioritario |
||
| 441 | * |
||
| 442 | * @param boolean $prioritario |
||
| 443 | * @return Parte |
||
| 444 | */ |
||
| 445 | public function setPrioritario($prioritario) |
||
| 446 | { |
||
| 447 | $this->prioritario = $prioritario; |
||
| 448 | |||
| 449 | return $this; |
||
| 450 | } |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Get prioritario |
||
| 454 | * |
||
| 455 | * @return boolean |
||
| 456 | */ |
||
| 457 | public function getPrioritario() |
||
| 458 | { |
||
| 459 | return $this->prioritario; |
||
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Set fechaRecordatorio |
||
| 464 | * |
||
| 465 | * @param \DateTime $fechaRecordatorio |
||
| 466 | * @return Parte |
||
| 467 | */ |
||
| 468 | public function setFechaRecordatorio($fechaRecordatorio) |
||
| 469 | { |
||
| 470 | $this->fechaRecordatorio = $fechaRecordatorio; |
||
| 471 | |||
| 472 | return $this; |
||
| 473 | } |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Get fechaRecordatorio |
||
| 477 | * |
||
| 478 | * @return \DateTime |
||
| 479 | */ |
||
| 480 | public function getFechaRecordatorio() |
||
| 481 | { |
||
| 482 | return $this->fechaRecordatorio; |
||
| 483 | } |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Set hayExpulsion |
||
| 487 | * |
||
| 488 | * @param boolean $hayExpulsion |
||
| 489 | * @return Parte |
||
| 490 | */ |
||
| 491 | public function setHayExpulsion($hayExpulsion) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Get hayExpulsion |
||
| 500 | * |
||
| 501 | * @return boolean |
||
| 502 | */ |
||
| 503 | public function getHayExpulsion() |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Set actividadesRealizadas |
||
| 510 | * |
||
| 511 | * @param boolean $actividadesRealizadas |
||
| 512 | * @return Parte |
||
| 513 | */ |
||
| 514 | public function setActividadesRealizadas($actividadesRealizadas) |
||
| 515 | { |
||
| 516 | $this->actividadesRealizadas = $actividadesRealizadas; |
||
| 517 | |||
| 518 | return $this; |
||
| 519 | } |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Get actividadesRealizadas |
||
| 523 | * |
||
| 524 | * @return boolean |
||
| 525 | */ |
||
| 526 | public function getActividadesRealizadas() |
||
| 527 | { |
||
| 528 | return $this->actividadesRealizadas; |
||
| 529 | } |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Set tramo |
||
| 533 | * |
||
| 534 | * @param TramoParte $tramo |
||
| 535 | * @return Parte |
||
| 536 | */ |
||
| 537 | public function setTramo(TramoParte $tramo = null) |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Get tramo |
||
| 546 | * |
||
| 547 | * @return TramoParte |
||
| 548 | */ |
||
| 549 | public function getTramo() |
||
| 553 | |||
| 554 | /** |
||
| 555 | * Add conductas |
||
| 556 | * |
||
| 557 | * @param TipoConducta $conductas |
||
| 558 | * @return Parte |
||
| 559 | */ |
||
| 560 | public function addConducta(TipoConducta $conductas) |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Remove conductas |
||
| 569 | * |
||
| 570 | * @param TipoConducta $conductas |
||
| 571 | */ |
||
| 572 | public function removeConducta(TipoConducta $conductas) |
||
| 576 | |||
| 577 | /** |
||
| 578 | * Get conductas |
||
| 579 | * |
||
| 580 | * @return Collection |
||
| 581 | */ |
||
| 582 | public function getConductas() |
||
| 586 | |||
| 587 | public function __toString() |
||
| 591 | |||
| 592 | } |
||
| 593 |