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 |
||
| 33 | class Parte |
||
| 34 | { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @ORM\Id |
||
| 38 | * @ORM\Column(type="integer") |
||
| 39 | * @ORM\GeneratedValue |
||
| 40 | */ |
||
| 41 | protected $id; |
||
| 42 | /** |
||
| 43 | * @ORM\ManyToOne(targetEntity="Usuario", inversedBy="partes") |
||
| 44 | * @ORM\JoinColumn(nullable=false) |
||
| 45 | * @var Usuario |
||
| 46 | * |
||
| 47 | * @Assert\NotBlank() |
||
| 48 | */ |
||
| 49 | protected $usuario; |
||
| 50 | /** |
||
| 51 | * @ORM\ManyToOne(targetEntity="Alumno", inversedBy="partes") |
||
| 52 | * @ORM\JoinColumn(nullable=false) |
||
| 53 | * @var Alumno |
||
| 54 | */ |
||
| 55 | protected $alumno; |
||
| 56 | /** |
||
| 57 | * @ORM\Column(type="text", nullable=false) |
||
| 58 | * @var string |
||
| 59 | * |
||
| 60 | * @Assert\Length(min="10", minMessage="parte.anotacion.min_length") |
||
| 61 | */ |
||
| 62 | protected $anotacion; |
||
| 63 | /** |
||
| 64 | * @ORM\Column(type="text", nullable=true) |
||
| 65 | * @var string |
||
| 66 | * |
||
| 67 | * @Assert\NotBlank(groups={"expulsion"}, message="parte.actividades.expulsion") |
||
| 68 | */ |
||
| 69 | protected $actividades; |
||
| 70 | /** |
||
| 71 | * @ORM\Column(type="datetime", nullable=false) |
||
| 72 | * @var \DateTime |
||
| 73 | */ |
||
| 74 | protected $fechaCreacion; |
||
| 75 | /** |
||
| 76 | * @ORM\Column(type="datetime", nullable=false) |
||
| 77 | * @var \DateTime |
||
| 78 | * |
||
| 79 | * @Assert\NotBlank(groups={"nuevo"}, message="parte.fecha_suceso.not_blank") |
||
| 80 | * AssertDateRange(max="now +10 minute", maxMessage="parte.fecha_suceso.max") |
||
| 81 | */ |
||
| 82 | protected $fechaSuceso; |
||
| 83 | /** |
||
| 84 | * @ORM\ManyToOne(targetEntity="TramoParte") |
||
| 85 | * @ORM\JoinColumn(nullable=false) |
||
| 86 | * @var TramoParte |
||
| 87 | * |
||
| 88 | * @Assert\NotBlank(groups={"nuevo"}, message="parte.tramo.not_blank") |
||
| 89 | */ |
||
| 90 | protected $tramo; |
||
| 91 | /** |
||
| 92 | * @ORM\Column(type="datetime", nullable=true) |
||
| 93 | * @var \DateTime |
||
| 94 | */ |
||
| 95 | protected $fechaAviso; |
||
| 96 | /** |
||
| 97 | * @ORM\Column(type="datetime", nullable=true) |
||
| 98 | * @var boolean |
||
| 99 | */ |
||
| 100 | protected $fechaRecordatorio; |
||
| 101 | /** |
||
| 102 | * @ORM\Column(type="boolean", nullable=false) |
||
| 103 | * @var boolean |
||
| 104 | */ |
||
| 105 | protected $prescrito; |
||
| 106 | /** |
||
| 107 | * @ORM\Column(type="boolean", nullable=false) |
||
| 108 | * @var boolean |
||
| 109 | */ |
||
| 110 | protected $prioritario; |
||
| 111 | /** |
||
| 112 | * @ORM\Column(type="boolean", nullable=false) |
||
| 113 | * @var boolean |
||
| 114 | */ |
||
| 115 | protected $hayExpulsion; |
||
| 116 | /** |
||
| 117 | * @ORM\Column(type="boolean", nullable=true) |
||
| 118 | * @var boolean |
||
| 119 | */ |
||
| 120 | protected $actividadesRealizadas; |
||
| 121 | /** |
||
| 122 | * @ORM\ManyToMany(targetEntity="TipoConducta") |
||
| 123 | * @var Collection |
||
| 124 | * |
||
| 125 | * @Assert\Count(min="1", minMessage="parte.conductas.min") |
||
| 126 | */ |
||
| 127 | protected $conductas = null; |
||
| 128 | /** |
||
| 129 | * @ORM\ManyToOne(targetEntity="Sancion", inversedBy="partes") |
||
| 130 | * @var Sancion |
||
| 131 | */ |
||
| 132 | protected $sancion; |
||
| 133 | /** |
||
| 134 | * @ORM\OneToMany(targetEntity="ObservacionParte", mappedBy="parte") |
||
| 135 | * @var Collection |
||
| 136 | */ |
||
| 137 | protected $observaciones = null; |
||
| 138 | /** |
||
| 139 | * @ORM\OneToMany(targetEntity="AvisoParte", mappedBy="parte") |
||
| 140 | * @var Collection |
||
| 141 | */ |
||
| 142 | protected $avisos = null; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Constructor |
||
| 146 | */ |
||
| 147 | public function __construct() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Get id |
||
| 156 | * |
||
| 157 | * @return integer |
||
| 158 | */ |
||
| 159 | public function getId() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Set anotacion |
||
| 166 | * |
||
| 167 | * @param string $anotacion |
||
| 168 | * @return Parte |
||
| 169 | */ |
||
| 170 | public function setAnotacion($anotacion) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Get anotacion |
||
| 179 | * |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public function getAnotacion() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Set actividades |
||
| 189 | * |
||
| 190 | * @param string $actividades |
||
| 191 | * @return Parte |
||
| 192 | */ |
||
| 193 | public function setActividades($actividades) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Get actividades |
||
| 202 | * |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | public function getActividades() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Set fechaCreacion |
||
| 212 | * |
||
| 213 | * @param \DateTime $fechaCreacion |
||
| 214 | * @return Parte |
||
| 215 | */ |
||
| 216 | public function setFechaCreacion($fechaCreacion) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Get fechaCreacion |
||
| 225 | * |
||
| 226 | * @return \DateTime |
||
| 227 | */ |
||
| 228 | public function getFechaCreacion() |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Set fechaSuceso |
||
| 235 | * |
||
| 236 | * @param \DateTime $fechaSuceso |
||
| 237 | * @return Parte |
||
| 238 | */ |
||
| 239 | public function setFechaSuceso($fechaSuceso) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Get fechaSuceso |
||
| 248 | * |
||
| 249 | * @return \DateTime |
||
| 250 | */ |
||
| 251 | public function getFechaSuceso() |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Set fechaAviso |
||
| 258 | * |
||
| 259 | * @param \DateTime $fechaAviso |
||
| 260 | * @return Parte |
||
| 261 | */ |
||
| 262 | public function setFechaAviso($fechaAviso) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Get fechaAviso |
||
| 271 | * |
||
| 272 | * @return \DateTime |
||
| 273 | */ |
||
| 274 | public function getFechaAviso() |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Set usuario |
||
| 281 | * |
||
| 282 | * @param Usuario $usuario |
||
| 283 | * @return Parte |
||
| 284 | */ |
||
| 285 | public function setUsuario(Usuario $usuario = null) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Get usuario |
||
| 294 | * |
||
| 295 | * @return Usuario |
||
| 296 | */ |
||
| 297 | public function getUsuario() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * Set alumno |
||
| 304 | * |
||
| 305 | * @param Alumno $alumno |
||
| 306 | * @return Parte |
||
| 307 | */ |
||
| 308 | public function setAlumno(Alumno $alumno = null) |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Get alumno |
||
| 317 | * |
||
| 318 | * @return Alumno |
||
| 319 | */ |
||
| 320 | public function getAlumno() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * Set sancion |
||
| 327 | * |
||
| 328 | * @param Sancion $sancion |
||
| 329 | * @return Parte |
||
| 330 | */ |
||
| 331 | public function setSancion(Sancion $sancion = null) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * Get sancion |
||
| 340 | * |
||
| 341 | * @return Sancion |
||
| 342 | */ |
||
| 343 | public function getSancion() |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Add observaciones |
||
| 350 | * |
||
| 351 | * @param ObservacionParte $observaciones |
||
| 352 | * @return Parte |
||
| 353 | */ |
||
| 354 | public function addObservacion(ObservacionParte $observaciones) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Remove observaciones |
||
| 363 | * |
||
| 364 | * @param ObservacionParte $observaciones |
||
| 365 | */ |
||
| 366 | public function removeObservacion(ObservacionParte $observaciones) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * Get observaciones |
||
| 373 | * |
||
| 374 | * @return Collection |
||
| 375 | */ |
||
| 376 | public function getObservaciones() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Add avisos |
||
| 383 | * |
||
| 384 | * @param AvisoParte $avisos |
||
| 385 | * @return Parte |
||
| 386 | */ |
||
| 387 | public function addAviso(AvisoParte $avisos) |
||
| 393 | |||
| 394 | /** |
||
| 395 | * Remove avisos |
||
| 396 | * |
||
| 397 | * @param AvisoParte $avisos |
||
| 398 | */ |
||
| 399 | public function removeAviso(AvisoParte $avisos) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Get avisos |
||
| 406 | * |
||
| 407 | * @return Collection |
||
| 408 | */ |
||
| 409 | public function getAvisos() |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Set prescrito |
||
| 416 | * |
||
| 417 | * @param boolean $prescrito |
||
| 418 | * @return Parte |
||
| 419 | */ |
||
| 420 | public function setPrescrito($prescrito) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Get prescrito |
||
| 429 | * |
||
| 430 | * @return boolean |
||
| 431 | */ |
||
| 432 | public function getPrescrito() |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Set prioritario |
||
| 439 | * |
||
| 440 | * @param boolean $prioritario |
||
| 441 | * @return Parte |
||
| 442 | */ |
||
| 443 | public function setPrioritario($prioritario) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Get prioritario |
||
| 452 | * |
||
| 453 | * @return boolean |
||
| 454 | */ |
||
| 455 | public function getPrioritario() |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Set fechaRecordatorio |
||
| 462 | * |
||
| 463 | * @param \DateTime $fechaRecordatorio |
||
| 464 | * @return Parte |
||
| 465 | */ |
||
| 466 | public function setFechaRecordatorio($fechaRecordatorio) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Get fechaRecordatorio |
||
| 475 | * |
||
| 476 | * @return \DateTime |
||
| 477 | */ |
||
| 478 | public function getFechaRecordatorio() |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Set hayExpulsion |
||
| 485 | * |
||
| 486 | * @param boolean $hayExpulsion |
||
| 487 | * @return Parte |
||
| 488 | */ |
||
| 489 | public function setHayExpulsion($hayExpulsion) |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Get hayExpulsion |
||
| 498 | * |
||
| 499 | * @return boolean |
||
| 500 | */ |
||
| 501 | public function getHayExpulsion() |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Set actividadesRealizadas |
||
| 508 | * |
||
| 509 | * @param boolean $actividadesRealizadas |
||
| 510 | * @return Parte |
||
| 511 | */ |
||
| 512 | public function setActividadesRealizadas($actividadesRealizadas) |
||
| 518 | |||
| 519 | /** |
||
| 520 | * Get actividadesRealizadas |
||
| 521 | * |
||
| 522 | * @return boolean |
||
| 523 | */ |
||
| 524 | public function getActividadesRealizadas() |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Set tramo |
||
| 531 | * |
||
| 532 | * @param TramoParte $tramo |
||
| 533 | * @return Parte |
||
| 534 | */ |
||
| 535 | public function setTramo(TramoParte $tramo = null) |
||
| 541 | |||
| 542 | /** |
||
| 543 | * Get tramo |
||
| 544 | * |
||
| 545 | * @return TramoParte |
||
| 546 | */ |
||
| 547 | public function getTramo() |
||
| 551 | |||
| 552 | /** |
||
| 553 | * Add conductas |
||
| 554 | * |
||
| 555 | * @param TipoConducta $conductas |
||
| 556 | * @return Parte |
||
| 557 | */ |
||
| 558 | public function addConducta(TipoConducta $conductas) |
||
| 564 | |||
| 565 | /** |
||
| 566 | * Remove conductas |
||
| 567 | * |
||
| 568 | * @param TipoConducta $conductas |
||
| 569 | */ |
||
| 570 | public function removeConducta(TipoConducta $conductas) |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Get conductas |
||
| 577 | * |
||
| 578 | * @return Collection |
||
| 579 | */ |
||
| 580 | public function getConductas() |
||
| 584 | |||
| 585 | public function __toString() |
||
| 589 | |||
| 590 | } |
||
| 591 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..