Complex classes like Usuario 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 Usuario, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 34 | class Usuario implements AdvancedUserInterface |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * @ORM\Id |
||
| 38 | * @ORM\Column(type="integer") |
||
| 39 | * @ORM\GeneratedValue |
||
| 40 | */ |
||
| 41 | protected $id; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @ORM\Column(type="string") |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $nombreUsuario; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @ORM\Column(type="string") |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | protected $password; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @ORM\Column(type="string") |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | protected $nombre; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @ORM\Column(type="string") |
||
| 63 | * @var string |
||
| 64 | */ |
||
| 65 | protected $apellidos; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @ORM\Column(type="string", nullable=true) |
||
| 69 | * @var string |
||
| 70 | */ |
||
| 71 | protected $email; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @ORM\Column(type="boolean", options={"default": true}) |
||
| 75 | * @var boolean |
||
| 76 | */ |
||
| 77 | protected $notificaciones; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @ORM\Column(type="boolean", options={"default": false}) |
||
| 81 | * @var boolean |
||
| 82 | */ |
||
| 83 | protected $esAdministrador; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @ORM\Column(type="boolean", options={"default": false}) |
||
| 87 | * @var boolean |
||
| 88 | */ |
||
| 89 | protected $esRevisor; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @ORM\Column(type="boolean", options={"default": false}) |
||
| 93 | * @var boolean |
||
| 94 | */ |
||
| 95 | protected $esDirectivo; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @ORM\Column(type="boolean", options={"default": false}) |
||
| 99 | * @var boolean |
||
| 100 | */ |
||
| 101 | protected $esOrientador; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @ORM\Column(type="boolean", options={"default": true}) |
||
| 105 | * @var boolean |
||
| 106 | */ |
||
| 107 | protected $estaActivo; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @ORM\Column(type="boolean", options={"default": false}) |
||
| 111 | * @var boolean |
||
| 112 | */ |
||
| 113 | protected $estaBloqueado; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @ORM\ManyToOne(targetEntity="Grupo", inversedBy="tutores") |
||
| 117 | * @var Grupo |
||
| 118 | */ |
||
| 119 | protected $tutoria = null; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @ORM\OneToMany(targetEntity="Parte", mappedBy="usuario") |
||
| 123 | * @var Collection |
||
| 124 | */ |
||
| 125 | protected $partes = null; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @ORM\OneToMany(targetEntity="Sancion", mappedBy="usuario") |
||
| 129 | * @var Collection |
||
| 130 | */ |
||
| 131 | protected $sanciones = null; |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @ORM\Column(type="boolean", options={"default": false}) |
||
| 135 | * @var boolean |
||
| 136 | */ |
||
| 137 | protected $esExterno; |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Constructor |
||
| 141 | */ |
||
| 142 | public function __construct() |
||
| 143 | { |
||
| 144 | $this->partes = new ArrayCollection(); |
||
| 145 | $this->sanciones = new ArrayCollection(); |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * |
||
| 150 | * @return int |
||
| 151 | */ |
||
| 152 | public function getId() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * |
||
| 159 | * @return string |
||
| 160 | */ |
||
| 161 | public function getApellidos() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * |
||
| 168 | * @param string $valor |
||
| 169 | * @return Usuario |
||
| 170 | */ |
||
| 171 | public function setApellidos($valor) |
||
| 177 | |||
| 178 | |||
| 179 | /** |
||
| 180 | * |
||
| 181 | * @return string |
||
| 182 | */ |
||
| 183 | public function getEmail() |
||
| 187 | |||
| 188 | /** |
||
| 189 | * |
||
| 190 | * @param string|null $valor |
||
| 191 | * @return Usuario |
||
| 192 | */ |
||
| 193 | public function setEmail($valor) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * |
||
| 202 | * @return string |
||
| 203 | */ |
||
| 204 | public function __toString() { |
||
| 207 | |||
| 208 | /** |
||
| 209 | * |
||
| 210 | * @return string |
||
| 211 | */ |
||
| 212 | public function getNombre() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * |
||
| 219 | * @param string $valor |
||
| 220 | * @return Usuario |
||
| 221 | */ |
||
| 222 | public function setNombre($valor) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * Get tutoria |
||
| 231 | * |
||
| 232 | * @return Grupo |
||
| 233 | */ |
||
| 234 | public function getTutoria() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * |
||
| 241 | * @param Grupo|null $tutoria |
||
| 242 | * @return Usuario |
||
| 243 | */ |
||
| 244 | public function setTutoria($tutoria) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Add partes |
||
| 253 | * |
||
| 254 | * @param Parte $partes |
||
| 255 | * @return Usuario |
||
| 256 | */ |
||
| 257 | public function addParte(Parte $partes) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Remove partes |
||
| 266 | * |
||
| 267 | * @param Parte $partes |
||
| 268 | */ |
||
| 269 | public function removeParte(Parte $partes) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * Get partes |
||
| 276 | * |
||
| 277 | * @return Collection |
||
| 278 | */ |
||
| 279 | public function getPartes() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Get notificaciones |
||
| 286 | * |
||
| 287 | * @return boolean |
||
| 288 | */ |
||
| 289 | public function getNotificaciones() |
||
| 290 | { |
||
| 291 | return $this->notificaciones; |
||
| 292 | } |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Set notificaciones |
||
| 296 | * |
||
| 297 | * @param boolean $notificaciones |
||
| 298 | * @return Usuario |
||
| 299 | */ |
||
| 300 | public function setNotificaciones($notificaciones) |
||
| 301 | { |
||
| 302 | $this->notificaciones = $notificaciones; |
||
| 303 | |||
| 304 | return $this; |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Get esAdministrador |
||
| 309 | * |
||
| 310 | * @return boolean |
||
| 311 | */ |
||
| 312 | public function getEsAdministrador() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Set esAdministrador |
||
| 319 | * |
||
| 320 | * @param boolean $esAdministrador |
||
| 321 | * @return Usuario |
||
| 322 | */ |
||
| 323 | public function setEsAdministrador($esAdministrador) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Get esRevisor |
||
| 332 | * |
||
| 333 | * @return boolean |
||
| 334 | */ |
||
| 335 | public function getEsRevisor() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Set esRevisor |
||
| 342 | * |
||
| 343 | * @param boolean $esRevisor |
||
| 344 | * @return Usuario |
||
| 345 | */ |
||
| 346 | public function setEsRevisor($esRevisor) |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Get esOrientador |
||
| 355 | * |
||
| 356 | * @return boolean |
||
| 357 | */ |
||
| 358 | public function getEsOrientador() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Set esOrientador |
||
| 365 | * |
||
| 366 | * @param boolean $esOrientador |
||
| 367 | * @return Usuario |
||
| 368 | */ |
||
| 369 | public function setEsOrientador($esOrientador) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Get esDirectivo |
||
| 378 | * |
||
| 379 | * @return boolean |
||
| 380 | */ |
||
| 381 | public function getEsDirectivo() |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Set esAdministrador |
||
| 388 | * |
||
| 389 | * @param boolean $esDirectivo |
||
| 390 | * @return Usuario |
||
| 391 | */ |
||
| 392 | public function setEsDirectivo($esDirectivo) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Add sanciones |
||
| 401 | * |
||
| 402 | * @param Sancion $sanciones |
||
| 403 | * @return Usuario |
||
| 404 | */ |
||
| 405 | public function addSancion(Sancion $sanciones) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Remove sanciones |
||
| 414 | * |
||
| 415 | * @param Sancion $sanciones |
||
| 416 | */ |
||
| 417 | public function removeSancion(Sancion $sanciones) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Get sanciones |
||
| 424 | * |
||
| 425 | * @return Collection |
||
| 426 | */ |
||
| 427 | public function getSanciones() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Set nombreUsuario |
||
| 434 | * |
||
| 435 | * @param string $nombreUsuario |
||
| 436 | * @return Usuario |
||
| 437 | */ |
||
| 438 | public function setNombreUsuario($nombreUsuario) |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Get nombreUsuario |
||
| 447 | * |
||
| 448 | * @return string |
||
| 449 | */ |
||
| 450 | public function getNombreUsuario() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Set password |
||
| 457 | * |
||
| 458 | * @param string $password |
||
| 459 | * @return Usuario |
||
| 460 | */ |
||
| 461 | public function setPassword($password) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Get password |
||
| 470 | * |
||
| 471 | * @return string |
||
| 472 | */ |
||
| 473 | public function getPassword() |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Set estaActivo |
||
| 480 | * |
||
| 481 | * @param boolean $estaActivo |
||
| 482 | * @return Usuario |
||
| 483 | */ |
||
| 484 | public function setEstaActivo($estaActivo) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * Get estaActivo |
||
| 493 | * |
||
| 494 | * @return boolean |
||
| 495 | */ |
||
| 496 | public function getEstaActivo() |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Set estaBloqueado |
||
| 503 | * |
||
| 504 | * @param boolean $estaBloqueado |
||
| 505 | * @return Usuario |
||
| 506 | */ |
||
| 507 | public function setEstaBloqueado($estaBloqueado) |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Get estaBloqueado |
||
| 516 | * |
||
| 517 | * @return boolean |
||
| 518 | */ |
||
| 519 | public function getEstaBloqueado() |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Checks whether the user's account has expired. |
||
| 526 | * |
||
| 527 | * Internally, if this method returns false, the authentication system |
||
| 528 | * will throw an AccountExpiredException and prevent login. |
||
| 529 | * |
||
| 530 | * @return bool true if the user's account is non expired, false otherwise |
||
| 531 | * |
||
| 532 | * @see AccountExpiredException |
||
| 533 | */ |
||
| 534 | public function isAccountNonExpired() |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Checks whether the user is locked. |
||
| 541 | * |
||
| 542 | * Internally, if this method returns false, the authentication system |
||
| 543 | * will throw a LockedException and prevent login. |
||
| 544 | * |
||
| 545 | * @return bool true if the user is not locked, false otherwise |
||
| 546 | * |
||
| 547 | * @see LockedException |
||
| 548 | */ |
||
| 549 | public function isAccountNonLocked() |
||
| 553 | |||
| 554 | /** |
||
| 555 | * Checks whether the user's credentials (password) has expired. |
||
| 556 | * |
||
| 557 | * Internally, if this method returns false, the authentication system |
||
| 558 | * will throw a CredentialsExpiredException and prevent login. |
||
| 559 | * |
||
| 560 | * @return bool true if the user's credentials are non expired, false otherwise |
||
| 561 | * |
||
| 562 | * @see CredentialsExpiredException |
||
| 563 | */ |
||
| 564 | public function isCredentialsNonExpired() |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Checks whether the user is enabled. |
||
| 571 | * |
||
| 572 | * Internally, if this method returns false, the authentication system |
||
| 573 | * will throw a DisabledException and prevent login. |
||
| 574 | * |
||
| 575 | * @return bool true if the user is enabled, false otherwise |
||
| 576 | * |
||
| 577 | * @see DisabledException |
||
| 578 | */ |
||
| 579 | public function isEnabled() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Returns the roles granted to the user. |
||
| 586 | * |
||
| 587 | * <code> |
||
| 588 | * public function getRoles() |
||
| 589 | * { |
||
| 590 | * return array('ROLE_USER'); |
||
| 591 | * } |
||
| 592 | * </code> |
||
| 593 | * |
||
| 594 | * Alternatively, the roles might be stored on a ``roles`` property, |
||
| 595 | * and populated in any number of different ways when the user object |
||
| 596 | * is created. |
||
| 597 | * |
||
| 598 | * @return Role[] The user roles |
||
| 599 | */ |
||
| 600 | public function getRoles() |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Returns the salt that was originally used to encode the password. |
||
| 631 | * |
||
| 632 | * This can return null if the password was not encoded using a salt. |
||
| 633 | * |
||
| 634 | * @return string|null The salt |
||
| 635 | */ |
||
| 636 | public function getSalt() |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Returns the username used to authenticate the user. |
||
| 643 | * |
||
| 644 | * @return string The username |
||
| 645 | */ |
||
| 646 | public function getUsername() |
||
| 650 | |||
| 651 | /** |
||
| 652 | * Removes sensitive data from the user. |
||
| 653 | * |
||
| 654 | * This is important if, at any given point, sensitive information like |
||
| 655 | * the plain-text password is stored on this object. |
||
| 656 | */ |
||
| 657 | public function eraseCredentials() |
||
| 661 | |||
| 662 | /** |
||
| 663 | * @return bool |
||
| 664 | */ |
||
| 665 | public function getEsExterno() |
||
| 669 | |||
| 670 | /** |
||
| 671 | * @param bool $esExterno |
||
| 672 | * |
||
| 673 | * @return Usuario |
||
| 674 | */ |
||
| 675 | public function setEsExterno($esExterno) |
||
| 680 | } |
||
| 681 |