Complex classes like User 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 User, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class User extends CoreUser |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Genre [M|Mme] |
||
| 24 | * @ORM\Column(name="gender", type="string", nullable=true) |
||
| 25 | * @JMS\Expose |
||
| 26 | * @Assert\Type("string") |
||
| 27 | */ |
||
| 28 | protected $gender; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Promo (format: '0*', ie 016, 017...) |
||
| 32 | * @ORM\Column(name="promo", type="string", nullable=true) |
||
| 33 | * @JMS\Expose |
||
| 34 | * @Assert\Type("string") |
||
| 35 | * @Assert\Length(min=2,max=3) |
||
| 36 | */ |
||
| 37 | protected $promo; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Département [1A|GCC|GCC-Archi|GMM|GI|IMI|VET|SEGF] |
||
| 41 | * @ORM\Column(name="department", type="string", nullable=true) |
||
| 42 | * @JMS\Expose |
||
| 43 | * @Assert\Type("string") |
||
| 44 | */ |
||
| 45 | protected $department; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Origine [CC|DD] |
||
| 49 | * @ORM\Column(name="origin", type="string", nullable=true) |
||
| 50 | * @JMS\Expose |
||
| 51 | * @Assert\Type("string") |
||
| 52 | */ |
||
| 53 | protected $origin; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Nationalité |
||
| 57 | * @ORM\Column(name="nationality", type="string", nullable=true) |
||
| 58 | * @JMS\Expose |
||
| 59 | * @Assert\Type("string") |
||
| 60 | */ |
||
| 61 | protected $nationality; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Chambre (M016, A53, 3èmeG), lieu de résidence |
||
| 65 | * @ORM\Column(name="location", type="string", nullable=true) |
||
| 66 | * @JMS\Expose |
||
| 67 | * @Assert\Type("string") |
||
| 68 | */ |
||
| 69 | protected $location; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Téléphone au format 06.12.34.56.78 |
||
| 73 | * @ORM\Column(name="phone", type="string", nullable=true) |
||
| 74 | * @JMS\Expose |
||
| 75 | * @Assert\Type("string") |
||
| 76 | */ |
||
| 77 | protected $phone; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Pseudo Skype |
||
| 81 | * @ORM\Column(name="skype", type="string", nullable=true) |
||
| 82 | * @JMS\Expose |
||
| 83 | * @Assert\Type("string") |
||
| 84 | */ |
||
| 85 | protected $skype; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Cotisant BDE |
||
| 89 | * @ORM\Column(name="allowedBde", type="boolean", nullable=true) |
||
| 90 | * @JMS\Expose |
||
| 91 | * @Assert\Type("boolean") |
||
| 92 | */ |
||
| 93 | protected $allowedBde; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Cotisant BDS |
||
| 97 | * @ORM\Column(name="allowedBds", type="boolean", nullable=true) |
||
| 98 | * @JMS\Expose |
||
| 99 | * @Assert\Type("boolean") |
||
| 100 | */ |
||
| 101 | protected $allowedBds; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * A fait le tutoriel d'intro ? |
||
| 105 | * @ORM\Column(name="tour", type="boolean", nullable=true) |
||
| 106 | * @JMS\Expose |
||
| 107 | * @Assert\Type("boolean") |
||
| 108 | */ |
||
| 109 | protected $tour; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Autorisation de rendre publiques les stats Foyer |
||
| 113 | * @ORM\Column(name="statsFoyer", type="boolean") |
||
| 114 | * @JMS\Expose |
||
| 115 | * @Assert\Type("boolean") |
||
| 116 | */ |
||
| 117 | protected $statsFoyer = true; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Autorisation de rendre publiques les stats PontHub |
||
| 121 | * @ORM\Column(name="statsPonthub", type="boolean") |
||
| 122 | * @JMS\Expose |
||
| 123 | * @Assert\Type("boolean") |
||
| 124 | */ |
||
| 125 | protected $statsPonthub = true; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Autorisation de rendre publiques les stats de la réponse D |
||
| 129 | * @ORM\Column(name="statsFacegame", type="boolean") |
||
| 130 | * @JMS\Expose |
||
| 131 | * @Assert\Type("boolean") |
||
| 132 | */ |
||
| 133 | protected $statsFacegame = true; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Solde Foyer |
||
| 137 | * @ORM\Column(name="balance", type="float", nullable=true) |
||
| 138 | * @JMS\Expose |
||
| 139 | * @Assert\Type("float") |
||
| 140 | */ |
||
| 141 | protected $balance = 0.0; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Activation des mails d'événements |
||
| 145 | * @ORM\Column(name="mailEvent", type="boolean") |
||
| 146 | * @JMS\Expose |
||
| 147 | * @Assert\Type("boolean") |
||
| 148 | */ |
||
| 149 | protected $mailEvent = true; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Activation des mails de modification d'événements |
||
| 153 | * @ORM\Column(name="mailModification", type="boolean") |
||
| 154 | * @JMS\Expose |
||
| 155 | * @Assert\Type("boolean") |
||
| 156 | */ |
||
| 157 | protected $mailModification = true; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Activation des mails de rappel de shotguns |
||
| 161 | * @ORM\Column(name="mailShotgun", type="boolean") |
||
| 162 | * @JMS\Expose |
||
| 163 | * @Assert\Type("boolean") |
||
| 164 | */ |
||
| 165 | protected $mailShotgun = true; |
||
| 166 | |||
| 167 | /** |
||
| 168 | * Achievements de l'utilisateur |
||
| 169 | * @ORM\OneToMany(targetEntity="KI\UserBundle\Entity\AchievementUser", mappedBy="user", orphanRemoval=true) |
||
| 170 | * @Assert\Valid() |
||
| 171 | */ |
||
| 172 | protected $achievements; |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Clubs de l'utilisateur |
||
| 176 | * @ORM\OneToMany(targetEntity="KI\UserBundle\Entity\ClubUser", mappedBy="user", orphanRemoval=true) |
||
| 177 | * @Assert\Valid() |
||
| 178 | */ |
||
| 179 | protected $clubs; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Téléchargements de l'utilisateur |
||
| 183 | * @ORM\OneToMany(targetEntity="KI\PonthubBundle\Entity\PonthubFileUser", mappedBy="user", orphanRemoval=true) |
||
| 184 | * @Assert\Valid() |
||
| 185 | */ |
||
| 186 | protected $downloads; |
||
| 187 | |||
| 188 | /** |
||
| 189 | * Transactions de l'utilisateur |
||
| 190 | * @ORM\OneToMany(targetEntity="KI\FoyerBundle\Entity\Transaction", mappedBy="user") |
||
| 191 | * @Assert\Valid() |
||
| 192 | */ |
||
| 193 | protected $transactions; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * Constructor |
||
| 197 | */ |
||
| 198 | public function __construct() |
||
| 207 | |||
| 208 | protected function acronyme() |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Set gender |
||
| 219 | * |
||
| 220 | * @param string $gender |
||
| 221 | * @return User |
||
| 222 | */ |
||
| 223 | public function setGender($gender) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Get gender |
||
| 232 | * |
||
| 233 | * @return string |
||
| 234 | */ |
||
| 235 | public function getGender() |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Set promo |
||
| 242 | * |
||
| 243 | * @param string $promo |
||
| 244 | * @return User |
||
| 245 | */ |
||
| 246 | public function setPromo($promo) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Get promo |
||
| 255 | * |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public function getPromo() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Set department |
||
| 265 | * |
||
| 266 | * @param string $department |
||
| 267 | * @return User |
||
| 268 | */ |
||
| 269 | public function setDepartment($department) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Get department |
||
| 278 | * |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | public function getDepartment() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Set origin |
||
| 288 | * |
||
| 289 | * @param string $origin |
||
| 290 | * @return User |
||
| 291 | */ |
||
| 292 | public function setOrigin($origin) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Get origin |
||
| 301 | * |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public function getOrigin() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * Set nationality |
||
| 311 | * |
||
| 312 | * @param string $nationality |
||
| 313 | * @return User |
||
| 314 | */ |
||
| 315 | public function setNationality($nationality) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Get nationality |
||
| 324 | * |
||
| 325 | * @return string |
||
| 326 | */ |
||
| 327 | public function getNationality() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * Set location |
||
| 334 | * |
||
| 335 | * @param string $location |
||
| 336 | * @return User |
||
| 337 | */ |
||
| 338 | public function setLocation($location) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Get location |
||
| 347 | * |
||
| 348 | * @return string |
||
| 349 | */ |
||
| 350 | public function getLocation() |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Set phone |
||
| 357 | * |
||
| 358 | * @param string $phone |
||
| 359 | * @return User |
||
| 360 | */ |
||
| 361 | public function setPhone($phone) |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Get phone |
||
| 370 | * |
||
| 371 | * @return string |
||
| 372 | */ |
||
| 373 | public function getPhone() |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Set skype |
||
| 380 | * |
||
| 381 | * @param string $skype |
||
| 382 | * @return User |
||
| 383 | */ |
||
| 384 | public function setSkype($skype) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Get skype |
||
| 393 | * |
||
| 394 | * @return string |
||
| 395 | */ |
||
| 396 | public function getSkype() |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Set allowedBde |
||
| 403 | * |
||
| 404 | * @param string $allowedBde |
||
| 405 | * @return User |
||
| 406 | */ |
||
| 407 | public function setAllowedBde($allowedBde) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * Get allowedBde |
||
| 416 | * |
||
| 417 | * @return string |
||
| 418 | */ |
||
| 419 | public function getAllowedBde() |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Set allowedBds |
||
| 426 | * |
||
| 427 | * @param string $allowedBds |
||
| 428 | * @return User |
||
| 429 | */ |
||
| 430 | public function setAllowedBds($allowedBds) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Get allowedBds |
||
| 439 | * |
||
| 440 | * @return string |
||
| 441 | */ |
||
| 442 | public function getAllowedBds() |
||
| 446 | |||
| 447 | /** |
||
| 448 | * Set tour |
||
| 449 | * |
||
| 450 | * @param string $tour |
||
| 451 | * @return User |
||
| 452 | */ |
||
| 453 | public function setTour($tour) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Get tour |
||
| 462 | * |
||
| 463 | * @return string |
||
| 464 | */ |
||
| 465 | public function getTour() |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Set statsFoyer |
||
| 472 | * |
||
| 473 | * @param bool $statsFoyer |
||
| 474 | * @return User |
||
| 475 | */ |
||
| 476 | public function setStatsFoyer($statsFoyer) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * Get statsFoyer |
||
| 485 | * |
||
| 486 | * @return string |
||
| 487 | */ |
||
| 488 | public function getStatsFoyer() |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Set statsPonthub |
||
| 495 | * |
||
| 496 | * @param bool $statsPonthub |
||
| 497 | * @return User |
||
| 498 | */ |
||
| 499 | public function setStatsPonthub($statsPonthub) |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Get statsPonthub |
||
| 508 | * |
||
| 509 | * @return string |
||
| 510 | */ |
||
| 511 | public function getStatsPonthub() |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Set statsFacegame |
||
| 518 | * |
||
| 519 | * @param bool $statsFacegame |
||
| 520 | * @return User |
||
| 521 | */ |
||
| 522 | public function setStatsFacegame($statsFacegame) |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Get statsFacegame |
||
| 531 | * |
||
| 532 | * @return string |
||
| 533 | */ |
||
| 534 | public function getStatsFacegame() |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Set balance |
||
| 541 | * |
||
| 542 | * @param string $balance |
||
| 543 | * @return User |
||
| 544 | */ |
||
| 545 | public function setBalance($balance) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Get balance |
||
| 553 | * |
||
| 554 | * @return \Doctrine\Common\Collections\Collection |
||
| 555 | */ |
||
| 556 | public function getBalance() |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Set mailEvent |
||
| 563 | * |
||
| 564 | * @param boolean $mailEvent |
||
| 565 | * @return User |
||
| 566 | */ |
||
| 567 | public function setMailEvent($mailEvent) |
||
| 573 | |||
| 574 | /** |
||
| 575 | * Get mailEvent |
||
| 576 | * |
||
| 577 | * @return boolean |
||
| 578 | */ |
||
| 579 | public function getMailEvent() |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Set mailShotgun |
||
| 586 | * |
||
| 587 | * @param boolean $mailShotgun |
||
| 588 | * @return User |
||
| 589 | */ |
||
| 590 | public function setMailShotgun($mailShotgun) |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Get mailShotgun |
||
| 599 | * |
||
| 600 | * @return boolean |
||
| 601 | */ |
||
| 602 | public function getMailShotgun() |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Set mailModification |
||
| 609 | * |
||
| 610 | * @param boolean $mailModification |
||
| 611 | * @return User |
||
| 612 | */ |
||
| 613 | public function setMailModification($mailModification) |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Get mailModification |
||
| 622 | * |
||
| 623 | * @return boolean |
||
| 624 | */ |
||
| 625 | public function getMailModification() |
||
| 629 | |||
| 630 | /** |
||
| 631 | * @return array |
||
| 632 | */ |
||
| 633 | public function getClubs() |
||
| 637 | } |
||
| 638 |