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 | * Notifications de l'utilisateur |
||
| 197 | * @ORM\ManyToMany(targetEntity="KI\UserBundle\Entity\Notification", mappedBy="recipients") |
||
| 198 | * @Assert\Valid() |
||
| 199 | */ |
||
| 200 | protected $notifications; |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Notifications lues de l'utilisateur |
||
| 204 | * @ORM\ManyToMany(targetEntity="KI\UserBundle\Entity\Notification", mappedBy="reads") |
||
| 205 | * @Assert\Valid() |
||
| 206 | */ |
||
| 207 | protected $notificationsRead; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Constructor |
||
| 211 | */ |
||
| 212 | public function __construct() |
||
| 221 | |||
| 222 | protected function acronyme() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Set gender |
||
| 233 | * |
||
| 234 | * @param string $gender |
||
| 235 | * @return User |
||
| 236 | */ |
||
| 237 | public function setGender($gender) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Get gender |
||
| 246 | * |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | public function getGender() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * Set promo |
||
| 256 | * |
||
| 257 | * @param string $promo |
||
| 258 | * @return User |
||
| 259 | */ |
||
| 260 | public function setPromo($promo) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * Get promo |
||
| 269 | * |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | public function getPromo() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Set department |
||
| 279 | * |
||
| 280 | * @param string $department |
||
| 281 | * @return User |
||
| 282 | */ |
||
| 283 | public function setDepartment($department) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Get department |
||
| 292 | * |
||
| 293 | * @return string |
||
| 294 | */ |
||
| 295 | public function getDepartment() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * Set origin |
||
| 302 | * |
||
| 303 | * @param string $origin |
||
| 304 | * @return User |
||
| 305 | */ |
||
| 306 | public function setOrigin($origin) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * Get origin |
||
| 315 | * |
||
| 316 | * @return string |
||
| 317 | */ |
||
| 318 | public function getOrigin() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Set nationality |
||
| 325 | * |
||
| 326 | * @param string $nationality |
||
| 327 | * @return User |
||
| 328 | */ |
||
| 329 | public function setNationality($nationality) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Get nationality |
||
| 338 | * |
||
| 339 | * @return string |
||
| 340 | */ |
||
| 341 | public function getNationality() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Set location |
||
| 348 | * |
||
| 349 | * @param string $location |
||
| 350 | * @return User |
||
| 351 | */ |
||
| 352 | public function setLocation($location) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Get location |
||
| 361 | * |
||
| 362 | * @return string |
||
| 363 | */ |
||
| 364 | public function getLocation() |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Set phone |
||
| 371 | * |
||
| 372 | * @param string $phone |
||
| 373 | * @return User |
||
| 374 | */ |
||
| 375 | public function setPhone($phone) |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Get phone |
||
| 384 | * |
||
| 385 | * @return string |
||
| 386 | */ |
||
| 387 | public function getPhone() |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Set skype |
||
| 394 | * |
||
| 395 | * @param string $skype |
||
| 396 | * @return User |
||
| 397 | */ |
||
| 398 | public function setSkype($skype) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Get skype |
||
| 407 | * |
||
| 408 | * @return string |
||
| 409 | */ |
||
| 410 | public function getSkype() |
||
| 414 | |||
| 415 | /** |
||
| 416 | * Set allowedBde |
||
| 417 | * |
||
| 418 | * @param string $allowedBde |
||
| 419 | * @return User |
||
| 420 | */ |
||
| 421 | public function setAllowedBde($allowedBde) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * Get allowedBde |
||
| 430 | * |
||
| 431 | * @return string |
||
| 432 | */ |
||
| 433 | public function getAllowedBde() |
||
| 437 | |||
| 438 | /** |
||
| 439 | * Set allowedBds |
||
| 440 | * |
||
| 441 | * @param string $allowedBds |
||
| 442 | * @return User |
||
| 443 | */ |
||
| 444 | public function setAllowedBds($allowedBds) |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Get allowedBds |
||
| 453 | * |
||
| 454 | * @return string |
||
| 455 | */ |
||
| 456 | public function getAllowedBds() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Set tour |
||
| 463 | * |
||
| 464 | * @param string $tour |
||
| 465 | * @return User |
||
| 466 | */ |
||
| 467 | public function setTour($tour) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * Get tour |
||
| 476 | * |
||
| 477 | * @return string |
||
| 478 | */ |
||
| 479 | public function getTour() |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Set statsFoyer |
||
| 486 | * |
||
| 487 | * @param bool $statsFoyer |
||
| 488 | * @return User |
||
| 489 | */ |
||
| 490 | public function setStatsFoyer($statsFoyer) |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Get statsFoyer |
||
| 499 | * |
||
| 500 | * @return string |
||
| 501 | */ |
||
| 502 | public function getStatsFoyer() |
||
| 506 | |||
| 507 | /** |
||
| 508 | * Set statsPonthub |
||
| 509 | * |
||
| 510 | * @param bool $statsPonthub |
||
| 511 | * @return User |
||
| 512 | */ |
||
| 513 | public function setStatsPonthub($statsPonthub) |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Get statsPonthub |
||
| 522 | * |
||
| 523 | * @return string |
||
| 524 | */ |
||
| 525 | public function getStatsPonthub() |
||
| 529 | |||
| 530 | /** |
||
| 531 | * Set statsFacegame |
||
| 532 | * |
||
| 533 | * @param bool $statsFacegame |
||
| 534 | * @return User |
||
| 535 | */ |
||
| 536 | public function setStatsFacegame($statsFacegame) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * Get statsFacegame |
||
| 545 | * |
||
| 546 | * @return string |
||
| 547 | */ |
||
| 548 | public function getStatsFacegame() |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Set balance |
||
| 555 | * |
||
| 556 | * @param string $balance |
||
| 557 | * @return User |
||
| 558 | */ |
||
| 559 | public function setBalance($balance) |
||
| 564 | |||
| 565 | /** |
||
| 566 | * Get balance |
||
| 567 | * |
||
| 568 | * @return \Doctrine\Common\Collections\Collection |
||
| 569 | */ |
||
| 570 | public function getBalance() |
||
| 574 | |||
| 575 | /** |
||
| 576 | * Set mailEvent |
||
| 577 | * |
||
| 578 | * @param boolean $mailEvent |
||
| 579 | * @return User |
||
| 580 | */ |
||
| 581 | public function setMailEvent($mailEvent) |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Get mailEvent |
||
| 590 | * |
||
| 591 | * @return boolean |
||
| 592 | */ |
||
| 593 | public function getMailEvent() |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Set mailShotgun |
||
| 600 | * |
||
| 601 | * @param boolean $mailShotgun |
||
| 602 | * @return User |
||
| 603 | */ |
||
| 604 | public function setMailShotgun($mailShotgun) |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Get mailShotgun |
||
| 613 | * |
||
| 614 | * @return boolean |
||
| 615 | */ |
||
| 616 | public function getMailShotgun() |
||
| 620 | |||
| 621 | /** |
||
| 622 | * Set mailModification |
||
| 623 | * |
||
| 624 | * @param boolean $mailModification |
||
| 625 | * @return User |
||
| 626 | */ |
||
| 627 | public function setMailModification($mailModification) |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Get mailModification |
||
| 636 | * |
||
| 637 | * @return boolean |
||
| 638 | */ |
||
| 639 | public function getMailModification() |
||
| 643 | |||
| 644 | /** |
||
| 645 | * @return array |
||
| 646 | */ |
||
| 647 | public function getClubs() |
||
| 651 | } |
||
| 652 |