Complex classes like CharCharacterSheet 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 CharCharacterSheet, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class CharCharacterSheet |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @ORM\Id @ORM\Column(name="characterID", type="bigint", options={"unsigned"=true}) |
||
| 16 | */ |
||
| 17 | private $characterId; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @ORM\Column(name="name", type="string") |
||
| 21 | */ |
||
| 22 | private $name; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @ORM\Column(name="DoB", type="datetime") |
||
| 26 | */ |
||
| 27 | private $dateOfBirth; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @ORM\Column(name="race", type="string") |
||
| 31 | */ |
||
| 32 | private $race; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @ORM\Column(name="bloodLine", type="string") |
||
| 36 | */ |
||
| 37 | private $bloodLine; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @ORM\Column(name="ancestry", type="string") |
||
| 41 | */ |
||
| 42 | private $ancestry; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @ORM\Column(name="gender", type="string") |
||
| 46 | */ |
||
| 47 | private $gender; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @ORM\Column(name="corporationID", type="bigint", options={"unsigned"=true}) |
||
| 51 | */ |
||
| 52 | private $corporationId; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @ORM\Column(name="corporationName", type="string") |
||
| 56 | */ |
||
| 57 | private $corporationName; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @ORM\Column(name="allianceID", type="bigint", options={"unsigned"=true}, nullable=true) |
||
| 61 | */ |
||
| 62 | private $allianceId; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @ORM\Column(name="allianceName", type="string", nullable=true) |
||
| 66 | */ |
||
| 67 | private $allianceName; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @ORM\Column(name="cloneName", type="string", nullable=true) |
||
| 71 | */ |
||
| 72 | private $cloneName; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @ORM\Column(name="cloneSkillPoints", type="bigint", options={"unsigned"=true}) |
||
| 76 | */ |
||
| 77 | private $cloneSkillPoints; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @ORM\Column(name="taxRate", type="decimal", precision=17, scale=2) |
||
| 81 | */ |
||
| 82 | private $balance; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var ArrayCollection |
||
| 86 | * @ORM\OneToMany(targetEntity="CharSkill", mappedBy="character", cascade="all") |
||
| 87 | */ |
||
| 88 | private $skills; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @ORM\OneToMany(targetEntity="CharCorporationRole", mappedBy="character", cascade="all") |
||
| 92 | */ |
||
| 93 | private $corporationRoles; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @ORM\OneToMany(targetEntity="CharCorporationRoleAtHq", mappedBy="character", cascade="all") |
||
| 97 | */ |
||
| 98 | private $corporationRolesAtHq; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @ORM\OneToMany(targetEntity="CharCorporationRoleAtBase", mappedBy="character", cascade="all") |
||
| 102 | */ |
||
| 103 | private $corporationRolesAtBase; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @ORM\OneToMany(targetEntity="CharCorporationRoleAtOther", mappedBy="character", cascade="all") |
||
| 107 | */ |
||
| 108 | private $corporationRolesAtOther; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @ORM\OneToMany(targetEntity="CharCorporationTitle", mappedBy="character", cascade="all") |
||
| 112 | */ |
||
| 113 | private $corporationTitles; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @ORM\OneToOne(targetEntity="CharAttributes", cascade="all") |
||
| 117 | * @JoinColumn(name="attributesId", referencedColumnName="id", onDelete="cascade") |
||
| 118 | */ |
||
| 119 | private $attributes; |
||
| 120 | |||
| 121 | |||
| 122 | public function __construct($characterId) |
||
| 123 | { |
||
| 124 | $this->characterId = $characterId; |
||
| 125 | $this->corporationRoles = new ArrayCollection(); |
||
| 126 | $this->corporationRolesAtHq = new ArrayCollection(); |
||
| 127 | $this->corporationRolesAtBase = new ArrayCollection(); |
||
| 128 | $this->corporationRolesAtOther = new ArrayCollection(); |
||
| 129 | $this->corporationTitles = new ArrayCollection(); |
||
| 130 | } |
||
| 131 | |||
| 132 | |||
| 133 | /** |
||
| 134 | * Set characterId |
||
| 135 | * |
||
| 136 | * @param integer $characterId |
||
| 137 | * @return CharCharacterSheet |
||
| 138 | */ |
||
| 139 | public function setCharacterId($characterId) |
||
| 140 | { |
||
| 141 | $this->characterId = $characterId; |
||
| 142 | |||
| 143 | return $this; |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Get characterId |
||
| 148 | * |
||
| 149 | * @return integer |
||
| 150 | */ |
||
| 151 | public function getCharacterId() |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Set name |
||
| 158 | * |
||
| 159 | * @param string $name |
||
| 160 | * @return CharCharacterSheet |
||
| 161 | */ |
||
| 162 | public function setName($name) |
||
| 163 | { |
||
| 164 | $this->name = $name; |
||
| 165 | |||
| 166 | return $this; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Get name |
||
| 171 | * |
||
| 172 | * @return string |
||
| 173 | */ |
||
| 174 | public function getName() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Set dateOfBirth |
||
| 181 | * |
||
| 182 | * @param \DateTime $dateOfBirth |
||
| 183 | * @return CharCharacterSheet |
||
| 184 | */ |
||
| 185 | public function setDateOfBirth($dateOfBirth) |
||
| 186 | { |
||
| 187 | $this->dateOfBirth = $dateOfBirth; |
||
| 188 | |||
| 189 | return $this; |
||
| 190 | } |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get dateOfBirth |
||
| 194 | * |
||
| 195 | * @return \DateTime |
||
| 196 | */ |
||
| 197 | public function getDateOfBirth() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Set race |
||
| 204 | * |
||
| 205 | * @param string $race |
||
| 206 | * @return CharCharacterSheet |
||
| 207 | */ |
||
| 208 | public function setRace($race) |
||
| 209 | { |
||
| 210 | $this->race = $race; |
||
| 211 | |||
| 212 | return $this; |
||
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * Get race |
||
| 217 | * |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | public function getRace() |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Set bloodLine |
||
| 227 | * |
||
| 228 | * @param string $bloodLine |
||
| 229 | * @return CharCharacterSheet |
||
| 230 | */ |
||
| 231 | public function setBloodLine($bloodLine) |
||
| 232 | { |
||
| 233 | $this->bloodLine = $bloodLine; |
||
| 234 | |||
| 235 | return $this; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Get bloodLine |
||
| 240 | * |
||
| 241 | * @return string |
||
| 242 | */ |
||
| 243 | public function getBloodLine() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Set ancestry |
||
| 250 | * |
||
| 251 | * @param string $ancestry |
||
| 252 | * @return CharCharacterSheet |
||
| 253 | */ |
||
| 254 | public function setAncestry($ancestry) |
||
| 255 | { |
||
| 256 | $this->ancestry = $ancestry; |
||
| 257 | |||
| 258 | return $this; |
||
| 259 | } |
||
| 260 | |||
| 261 | /** |
||
| 262 | * Get ancestry |
||
| 263 | * |
||
| 264 | * @return string |
||
| 265 | */ |
||
| 266 | public function getAncestry() |
||
| 270 | |||
| 271 | /** |
||
| 272 | * Set gender |
||
| 273 | * |
||
| 274 | * @param string $gender |
||
| 275 | * @return CharCharacterSheet |
||
| 276 | */ |
||
| 277 | public function setGender($gender) |
||
| 278 | { |
||
| 279 | $this->gender = $gender; |
||
| 280 | |||
| 281 | return $this; |
||
| 282 | } |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Get gender |
||
| 286 | * |
||
| 287 | * @return string |
||
| 288 | */ |
||
| 289 | public function getGender() |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Set corporationId |
||
| 296 | * |
||
| 297 | * @param integer $corporationId |
||
| 298 | * @return CharCharacterSheet |
||
| 299 | */ |
||
| 300 | public function setCorporationId($corporationId) |
||
| 301 | { |
||
| 302 | $this->corporationId = $corporationId; |
||
| 303 | |||
| 304 | return $this; |
||
| 305 | } |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Get corporationId |
||
| 309 | * |
||
| 310 | * @return integer |
||
| 311 | */ |
||
| 312 | public function getCorporationId() |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Set corporationName |
||
| 319 | * |
||
| 320 | * @param string $corporationName |
||
| 321 | * @return CharCharacterSheet |
||
| 322 | */ |
||
| 323 | public function setCorporationName($corporationName) |
||
| 324 | { |
||
| 325 | $this->corporationName = $corporationName; |
||
| 326 | |||
| 327 | return $this; |
||
| 328 | } |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Get corporationName |
||
| 332 | * |
||
| 333 | * @return string |
||
| 334 | */ |
||
| 335 | public function getCorporationName() |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Set allianceId |
||
| 342 | * |
||
| 343 | * @param integer $allianceId |
||
| 344 | * @return CharCharacterSheet |
||
| 345 | */ |
||
| 346 | public function setAllianceId($allianceId) |
||
| 347 | { |
||
| 348 | $this->allianceId = $allianceId; |
||
| 349 | |||
| 350 | return $this; |
||
| 351 | } |
||
| 352 | |||
| 353 | /** |
||
| 354 | * Get allianceId |
||
| 355 | * |
||
| 356 | * @return integer |
||
| 357 | */ |
||
| 358 | public function getAllianceId() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Set allianceName |
||
| 365 | * |
||
| 366 | * @param string $allianceName |
||
| 367 | * @return CharCharacterSheet |
||
| 368 | */ |
||
| 369 | public function setAllianceName($allianceName) |
||
| 370 | { |
||
| 371 | $this->allianceName = $allianceName; |
||
| 372 | |||
| 373 | return $this; |
||
| 374 | } |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Get allianceName |
||
| 378 | * |
||
| 379 | * @return string |
||
| 380 | */ |
||
| 381 | public function getAllianceName() |
||
| 385 | |||
| 386 | /** |
||
| 387 | * Set cloneName |
||
| 388 | * |
||
| 389 | * @param string $cloneName |
||
| 390 | * @return CharCharacterSheet |
||
| 391 | */ |
||
| 392 | public function setCloneName($cloneName) |
||
| 393 | { |
||
| 394 | $this->cloneName = $cloneName; |
||
| 395 | |||
| 396 | return $this; |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * Get cloneName |
||
| 401 | * |
||
| 402 | * @return string |
||
| 403 | */ |
||
| 404 | public function getCloneName() |
||
| 408 | |||
| 409 | /** |
||
| 410 | * Set cloneSkillPoints |
||
| 411 | * |
||
| 412 | * @param integer $cloneSkillPoints |
||
| 413 | * @return CharCharacterSheet |
||
| 414 | */ |
||
| 415 | public function setCloneSkillPoints($cloneSkillPoints) |
||
| 416 | { |
||
| 417 | $this->cloneSkillPoints = $cloneSkillPoints; |
||
| 418 | |||
| 419 | return $this; |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Get cloneSkillPoints |
||
| 424 | * |
||
| 425 | * @return integer |
||
| 426 | */ |
||
| 427 | public function getCloneSkillPoints() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * Set balance |
||
| 434 | * |
||
| 435 | * @param float $balance |
||
| 436 | * @return CharCharacterSheet |
||
| 437 | */ |
||
| 438 | public function setBalance($balance) |
||
| 439 | { |
||
| 440 | $this->balance = $balance; |
||
| 441 | |||
| 442 | return $this; |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Get balance |
||
| 447 | * |
||
| 448 | * @return float |
||
| 449 | */ |
||
| 450 | public function getBalance() |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Add skills |
||
| 457 | * |
||
| 458 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharSkill $skills |
||
| 459 | * @return CharCharacterSheet |
||
| 460 | */ |
||
| 461 | public function addSkill(\Tarioch\EveapiFetcherBundle\Entity\CharSkill $skills) |
||
| 462 | { |
||
| 463 | $this->skills[] = $skills; |
||
| 464 | |||
| 465 | return $this; |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * Remove skills |
||
| 470 | * |
||
| 471 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharSkill $skills |
||
| 472 | */ |
||
| 473 | public function removeSkill(\Tarioch\EveapiFetcherBundle\Entity\CharSkill $skills) |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Get skills |
||
| 480 | * |
||
| 481 | * @return \Doctrine\Common\Collections\Collection |
||
| 482 | */ |
||
| 483 | public function getSkills() |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Add corporationRoles |
||
| 490 | * |
||
| 491 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRole $corporationRoles |
||
| 492 | * @return CharCharacterSheet |
||
| 493 | */ |
||
| 494 | public function addCorporationRole(\Tarioch\EveapiFetcherBundle\Entity\CharCorporationRole $corporationRoles) |
||
| 495 | { |
||
| 496 | $this->corporationRoles[] = $corporationRoles; |
||
| 497 | |||
| 498 | return $this; |
||
| 499 | } |
||
| 500 | |||
| 501 | /** |
||
| 502 | * Remove corporationRoles |
||
| 503 | * |
||
| 504 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRole $corporationRoles |
||
| 505 | */ |
||
| 506 | public function removeCorporationRole(\Tarioch\EveapiFetcherBundle\Entity\CharCorporationRole $corporationRoles) |
||
| 510 | |||
| 511 | /** |
||
| 512 | * Get corporationRoles |
||
| 513 | * |
||
| 514 | * @return \Doctrine\Common\Collections\Collection |
||
| 515 | */ |
||
| 516 | public function getCorporationRoles() |
||
| 520 | |||
| 521 | /** |
||
| 522 | * Add corporationRolesAtHq |
||
| 523 | * |
||
| 524 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRoleAtHq $corporationRolesAtHq |
||
| 525 | * @return CharCharacterSheet |
||
| 526 | */ |
||
| 527 | public function addCorporationRolesAtHq(CharCorporationRoleAtHq $corporationRolesAtHq) |
||
| 528 | { |
||
| 529 | $this->corporationRolesAtHq[] = $corporationRolesAtHq; |
||
| 530 | |||
| 531 | return $this; |
||
| 532 | } |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Remove corporationRolesAtHq |
||
| 536 | * |
||
| 537 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRoleAtHq $corporationRolesAtHq |
||
| 538 | */ |
||
| 539 | public function removeCorporationRolesAtHq(CharCorporationRoleAtHq $corporationRolesAtHq) |
||
| 543 | |||
| 544 | /** |
||
| 545 | * Get corporationRolesAtHq |
||
| 546 | * |
||
| 547 | * @return \Doctrine\Common\Collections\Collection |
||
| 548 | */ |
||
| 549 | public function getCorporationRolesAtHq() |
||
| 553 | |||
| 554 | /** |
||
| 555 | * Add corporationRolesAtBase |
||
| 556 | * |
||
| 557 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRoleAtBase $corporationRolesAtBase |
||
| 558 | * @return CharCharacterSheet |
||
| 559 | */ |
||
| 560 | public function addCorporationRolesAtBase(CharCorporationRoleAtBase $corporationRolesAtBase) |
||
| 561 | { |
||
| 562 | $this->corporationRolesAtBase[] = $corporationRolesAtBase; |
||
| 563 | |||
| 564 | return $this; |
||
| 565 | } |
||
| 566 | |||
| 567 | /** |
||
| 568 | * Remove corporationRolesAtBase |
||
| 569 | * |
||
| 570 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRoleAtBase $corporationRolesAtBase |
||
| 571 | */ |
||
| 572 | public function removeCorporationRolesAtBase(CharCorporationRoleAtBase $corporationRolesAtBase) |
||
| 576 | |||
| 577 | /** |
||
| 578 | * Get corporationRolesAtBase |
||
| 579 | * |
||
| 580 | * @return \Doctrine\Common\Collections\Collection |
||
| 581 | */ |
||
| 582 | public function getCorporationRolesAtBase() |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Add corporationRolesAtOther |
||
| 589 | * |
||
| 590 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRoleAtOther $corporationRolesAtOther |
||
| 591 | * @return CharCharacterSheet |
||
| 592 | */ |
||
| 593 | public function addCorporationRolesAtOther(CharCorporationRoleAtOther $corporationRolesAtOther) |
||
| 594 | { |
||
| 595 | $this->corporationRolesAtOther[] = $corporationRolesAtOther; |
||
| 596 | |||
| 597 | return $this; |
||
| 598 | } |
||
| 599 | |||
| 600 | /** |
||
| 601 | * Remove corporationRolesAtOther |
||
| 602 | * |
||
| 603 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationRoleAtOther $corporationRolesAtOther |
||
| 604 | */ |
||
| 605 | public function removeCorporationRolesAtOther(CharCorporationRoleAtOther $corporationRolesAtOther) |
||
| 609 | |||
| 610 | /** |
||
| 611 | * Get corporationRolesAtOther |
||
| 612 | * |
||
| 613 | * @return \Doctrine\Common\Collections\Collection |
||
| 614 | */ |
||
| 615 | public function getCorporationRolesAtOther() |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Add corporationTitles |
||
| 622 | * |
||
| 623 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationTitle $corporationTitles |
||
| 624 | * @return CharCharacterSheet |
||
| 625 | */ |
||
| 626 | public function addCorporationTitle(\Tarioch\EveapiFetcherBundle\Entity\CharCorporationTitle $corporationTitles) |
||
| 627 | { |
||
| 628 | $this->corporationTitles[] = $corporationTitles; |
||
| 629 | |||
| 630 | return $this; |
||
| 631 | } |
||
| 632 | |||
| 633 | /** |
||
| 634 | * Remove corporationTitles |
||
| 635 | * |
||
| 636 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharCorporationTitle $corporationTitles |
||
| 637 | */ |
||
| 638 | public function removeCorporationTitle(\Tarioch\EveapiFetcherBundle\Entity\CharCorporationTitle $corporationTitles) |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Get corporationTitles |
||
| 645 | * |
||
| 646 | * @return \Doctrine\Common\Collections\Collection |
||
| 647 | */ |
||
| 648 | public function getCorporationTitles() |
||
| 652 | |||
| 653 | /** |
||
| 654 | * Set attributes |
||
| 655 | * |
||
| 656 | * @param \Tarioch\EveapiFetcherBundle\Entity\CharAttributes $attributes |
||
| 657 | * @return CharCharacterSheet |
||
| 658 | */ |
||
| 659 | public function setAttributes(\Tarioch\EveapiFetcherBundle\Entity\CharAttributes $attributes = null) |
||
| 660 | { |
||
| 661 | $this->attributes = $attributes; |
||
| 662 | |||
| 663 | return $this; |
||
| 664 | } |
||
| 665 | |||
| 666 | /** |
||
| 667 | * Get attributes |
||
| 668 | * |
||
| 669 | * @return \Tarioch\EveapiFetcherBundle\Entity\CharAttributes |
||
| 670 | */ |
||
| 671 | public function getAttributes() |
||
| 675 | } |
||
| 676 |