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 | * Constructor |
||
| 135 | */ |
||
| 136 | public function __construct() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * |
||
| 144 | * @return int |
||
| 145 | */ |
||
| 146 | public function getId() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * |
||
| 153 | * @return string |
||
| 154 | */ |
||
| 155 | public function getApellidos() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * |
||
| 162 | * @param string $valor |
||
| 163 | * @return Usuario |
||
| 164 | */ |
||
| 165 | public function setApellidos($valor) |
||
| 171 | |||
| 172 | |||
| 173 | /** |
||
| 174 | * |
||
| 175 | * @return string |
||
| 176 | */ |
||
| 177 | public function getEmail() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * |
||
| 184 | * @param string|null $valor |
||
| 185 | * @return Usuario |
||
| 186 | */ |
||
| 187 | public function setEmail($valor) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | public function __toString() { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * |
||
| 204 | * @return string |
||
| 205 | */ |
||
| 206 | public function getNombre() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * |
||
| 213 | * @param string $valor |
||
| 214 | * @return Usuario |
||
| 215 | */ |
||
| 216 | public function setNombre($valor) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Get tutoria |
||
| 225 | * |
||
| 226 | * @return Grupo |
||
| 227 | */ |
||
| 228 | public function getTutoria() |
||
| 232 | |||
| 233 | /** |
||
| 234 | * |
||
| 235 | * @param Grupo|null $tutoria |
||
| 236 | * @return Usuario |
||
| 237 | */ |
||
| 238 | public function setTutoria($tutoria) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * Add partes |
||
| 247 | * |
||
| 248 | * @param Parte $partes |
||
| 249 | * @return Usuario |
||
| 250 | */ |
||
| 251 | public function addParte(Parte $partes) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Remove partes |
||
| 260 | * |
||
| 261 | * @param Parte $partes |
||
| 262 | */ |
||
| 263 | public function removeParte(Parte $partes) |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Get partes |
||
| 270 | * |
||
| 271 | * @return Collection |
||
| 272 | */ |
||
| 273 | public function getPartes() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Get notificaciones |
||
| 280 | * |
||
| 281 | * @return boolean |
||
| 282 | */ |
||
| 283 | public function getNotificaciones() |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Set notificaciones |
||
| 290 | * |
||
| 291 | * @param boolean $notificaciones |
||
| 292 | * @return Usuario |
||
| 293 | */ |
||
| 294 | public function setNotificaciones($notificaciones) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Get esAdministrador |
||
| 303 | * |
||
| 304 | * @return boolean |
||
| 305 | */ |
||
| 306 | public function getEsAdministrador() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Set esAdministrador |
||
| 313 | * |
||
| 314 | * @param boolean $esAdministrador |
||
| 315 | * @return Usuario |
||
| 316 | */ |
||
| 317 | public function setEsAdministrador($esAdministrador) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Get esRevisor |
||
| 326 | * |
||
| 327 | * @return boolean |
||
| 328 | */ |
||
| 329 | public function getEsRevisor() |
||
| 333 | |||
| 334 | /** |
||
| 335 | * Set esRevisor |
||
| 336 | * |
||
| 337 | * @param boolean $esRevisor |
||
| 338 | * @return Usuario |
||
| 339 | */ |
||
| 340 | public function setEsRevisor($esRevisor) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Get esOrientador |
||
| 349 | * |
||
| 350 | * @return boolean |
||
| 351 | */ |
||
| 352 | public function getEsOrientador() |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Set esOrientador |
||
| 359 | * |
||
| 360 | * @param boolean $esOrientador |
||
| 361 | * @return Usuario |
||
| 362 | */ |
||
| 363 | public function setEsOrientador($esOrientador) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Get esDirectivo |
||
| 372 | * |
||
| 373 | * @return boolean |
||
| 374 | */ |
||
| 375 | public function getEsDirectivo() |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Set esAdministrador |
||
| 382 | * |
||
| 383 | * @param boolean $esDirectivo |
||
| 384 | * @return Usuario |
||
| 385 | */ |
||
| 386 | public function setEsDirectivo($esDirectivo) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * Add sanciones |
||
| 395 | * |
||
| 396 | * @param Sancion $sanciones |
||
| 397 | * @return Usuario |
||
| 398 | */ |
||
| 399 | public function addSancion(Sancion $sanciones) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Remove sanciones |
||
| 408 | * |
||
| 409 | * @param Sancion $sanciones |
||
| 410 | */ |
||
| 411 | public function removeSancion(Sancion $sanciones) |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Get sanciones |
||
| 418 | * |
||
| 419 | * @return Collection |
||
| 420 | */ |
||
| 421 | public function getSanciones() |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Set nombreUsuario |
||
| 428 | * |
||
| 429 | * @param string $nombreUsuario |
||
| 430 | * @return Usuario |
||
| 431 | */ |
||
| 432 | public function setNombreUsuario($nombreUsuario) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Get nombreUsuario |
||
| 441 | * |
||
| 442 | * @return string |
||
| 443 | */ |
||
| 444 | public function getNombreUsuario() |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Set password |
||
| 451 | * |
||
| 452 | * @param string $password |
||
| 453 | * @return Usuario |
||
| 454 | */ |
||
| 455 | public function setPassword($password) |
||
| 461 | |||
| 462 | /** |
||
| 463 | * Get password |
||
| 464 | * |
||
| 465 | * @return string |
||
| 466 | */ |
||
| 467 | public function getPassword() |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Set estaActivo |
||
| 474 | * |
||
| 475 | * @param boolean $estaActivo |
||
| 476 | * @return Usuario |
||
| 477 | */ |
||
| 478 | public function setEstaActivo($estaActivo) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Get estaActivo |
||
| 487 | * |
||
| 488 | * @return boolean |
||
| 489 | */ |
||
| 490 | public function getEstaActivo() |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Set estaBloqueado |
||
| 497 | * |
||
| 498 | * @param boolean $estaBloqueado |
||
| 499 | * @return Usuario |
||
| 500 | */ |
||
| 501 | public function setEstaBloqueado($estaBloqueado) |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Get estaBloqueado |
||
| 510 | * |
||
| 511 | * @return boolean |
||
| 512 | */ |
||
| 513 | public function getEstaBloqueado() |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Checks whether the user's account has expired. |
||
| 520 | * |
||
| 521 | * Internally, if this method returns false, the authentication system |
||
| 522 | * will throw an AccountExpiredException and prevent login. |
||
| 523 | * |
||
| 524 | * @return bool true if the user's account is non expired, false otherwise |
||
| 525 | * |
||
| 526 | * @see AccountExpiredException |
||
| 527 | */ |
||
| 528 | public function isAccountNonExpired() |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Checks whether the user is locked. |
||
| 535 | * |
||
| 536 | * Internally, if this method returns false, the authentication system |
||
| 537 | * will throw a LockedException and prevent login. |
||
| 538 | * |
||
| 539 | * @return bool true if the user is not locked, false otherwise |
||
| 540 | * |
||
| 541 | * @see LockedException |
||
| 542 | */ |
||
| 543 | public function isAccountNonLocked() |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Checks whether the user's credentials (password) has expired. |
||
| 550 | * |
||
| 551 | * Internally, if this method returns false, the authentication system |
||
| 552 | * will throw a CredentialsExpiredException and prevent login. |
||
| 553 | * |
||
| 554 | * @return bool true if the user's credentials are non expired, false otherwise |
||
| 555 | * |
||
| 556 | * @see CredentialsExpiredException |
||
| 557 | */ |
||
| 558 | public function isCredentialsNonExpired() |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Checks whether the user is enabled. |
||
| 565 | * |
||
| 566 | * Internally, if this method returns false, the authentication system |
||
| 567 | * will throw a DisabledException and prevent login. |
||
| 568 | * |
||
| 569 | * @return bool true if the user is enabled, false otherwise |
||
| 570 | * |
||
| 571 | * @see DisabledException |
||
| 572 | */ |
||
| 573 | public function isEnabled() |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Returns the roles granted to the user. |
||
| 580 | * |
||
| 581 | * <code> |
||
| 582 | * public function getRoles() |
||
| 583 | * { |
||
| 584 | * return array('ROLE_USER'); |
||
| 585 | * } |
||
| 586 | * </code> |
||
| 587 | * |
||
| 588 | * Alternatively, the roles might be stored on a ``roles`` property, |
||
| 589 | * and populated in any number of different ways when the user object |
||
| 590 | * is created. |
||
| 591 | * |
||
| 592 | * @return Role[] The user roles |
||
| 593 | */ |
||
| 594 | public function getRoles() |
||
| 622 | |||
| 623 | /** |
||
| 624 | * Returns the salt that was originally used to encode the password. |
||
| 625 | * |
||
| 626 | * This can return null if the password was not encoded using a salt. |
||
| 627 | * |
||
| 628 | * @return string|null The salt |
||
| 629 | */ |
||
| 630 | public function getSalt() |
||
| 634 | |||
| 635 | /** |
||
| 636 | * Returns the username used to authenticate the user. |
||
| 637 | * |
||
| 638 | * @return string The username |
||
| 639 | */ |
||
| 640 | public function getUsername() |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Removes sensitive data from the user. |
||
| 647 | * |
||
| 648 | * This is important if, at any given point, sensitive information like |
||
| 649 | * the plain-text password is stored on this object. |
||
| 650 | */ |
||
| 651 | public function eraseCredentials() |
||
| 655 | } |
||
| 656 |