Complex classes like DoctrineDonation 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 DoctrineDonation, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class DoctrineDonation { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @since 2.0 |
||
| 19 | */ |
||
| 20 | const STATUS_NEW = 'N'; // status for direct debit |
||
| 21 | const STATUS_PROMISE = 'Z'; // status for bank transfer |
||
| 22 | const STATUS_EXTERNAL_INCOMPLETE = 'X'; // status for external payments |
||
| 23 | const STATUS_EXTERNAL_BOOKED = 'B'; // status for external payments |
||
| 24 | const STATUS_MODERATION = 'P'; |
||
| 25 | const STATUS_CANCELLED = 'D'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var integer |
||
| 29 | * |
||
| 30 | * @ORM\Column(name="id", type="integer") |
||
| 31 | * @ORM\Id |
||
| 32 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 33 | */ |
||
| 34 | private $id; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | * |
||
| 39 | * @ORM\Column(name="status", type="string", length=1, options={"default":"N", "fixed":true}, nullable=false) |
||
| 40 | */ |
||
| 41 | private $status = self::STATUS_NEW; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | * |
||
| 46 | * @ORM\Column(name="name", type="string", length=250, nullable=true) |
||
| 47 | */ |
||
| 48 | private $donorFullName; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | * |
||
| 53 | * @ORM\Column(name="ort", type="string", length=250, nullable=true) |
||
| 54 | */ |
||
| 55 | private $donorCity; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | * |
||
| 60 | * @ORM\Column(name="email", type="string", length=250, nullable=true) |
||
| 61 | */ |
||
| 62 | private $donorEmail; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var boolean |
||
| 66 | * |
||
| 67 | * @ORM\Column(name="info", type="boolean", options={"default":0}, nullable=false) |
||
| 68 | */ |
||
| 69 | private $donorOptsIntoNewsletter = 0; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var boolean |
||
| 73 | * |
||
| 74 | * @ORM\Column(name="bescheinigung", type="boolean", nullable=true) |
||
| 75 | */ |
||
| 76 | private $donationReceipt; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string |
||
| 80 | * |
||
| 81 | * @ORM\Column(name="eintrag", type="string", length=250, options={"default":""}, nullable=false) |
||
| 82 | */ |
||
| 83 | private $publicRecord = ''; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var string |
||
| 87 | * |
||
| 88 | * @ORM\Column(name="betrag", type="string", length=250, nullable=true) |
||
| 89 | */ |
||
| 90 | private $amount; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var integer |
||
| 94 | * |
||
| 95 | * @ORM\Column(name="periode", type="smallint", options={"default":0}, nullable=false) |
||
| 96 | */ |
||
| 97 | private $paymentIntervalInMonths = 0; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | * |
||
| 102 | * @ORM\Column(name="zahlweise", type="string", length=3, options={"default":"BEZ", "fixed":true}, nullable=false) |
||
| 103 | */ |
||
| 104 | private $paymentType = 'BEZ'; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var string |
||
| 108 | * |
||
| 109 | * @ORM\Column(name="kommentar", type="text", options={"default":""}, nullable=false) |
||
| 110 | */ |
||
| 111 | private $comment = ''; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var string |
||
| 115 | * |
||
| 116 | * @ORM\Column(name="ueb_code", type="string", length=32, options={"default":""}, nullable=false) |
||
| 117 | */ |
||
| 118 | private $bankTransferCode = ''; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var string |
||
| 122 | * |
||
| 123 | * @ORM\Column(name="data", type="text", nullable=true) |
||
| 124 | */ |
||
| 125 | private $data; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var string |
||
| 129 | * |
||
| 130 | * @ORM\Column(name="source", type="string", length=250, nullable=true) |
||
| 131 | */ |
||
| 132 | private $source; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @var string |
||
| 136 | * |
||
| 137 | * @ORM\Column(name="remote_addr", type="string", length=250, options={"default":""}, nullable=false) |
||
| 138 | */ |
||
| 139 | private $remoteAddr = ''; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var string |
||
| 143 | * |
||
| 144 | * @ORM\Column(name="hash", type="string", length=250, nullable=true) |
||
| 145 | */ |
||
| 146 | private $hash; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @var boolean |
||
| 150 | * |
||
| 151 | * @ORM\Column(name="is_public", type="boolean", options={"default":0}, nullable=false) |
||
| 152 | */ |
||
| 153 | private $isPublic = 0; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @var \DateTime |
||
| 157 | * |
||
| 158 | * @Gedmo\Timestampable(on="create") |
||
| 159 | * @ORM\Column(name="dt_new", type="datetime") |
||
| 160 | */ |
||
| 161 | private $creationTime; |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @var \DateTime |
||
| 165 | * |
||
| 166 | * @ORM\Column(name="dt_del", type="datetime", nullable=true) |
||
| 167 | */ |
||
| 168 | private $deletionTime; |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @var \DateTime |
||
| 172 | * |
||
| 173 | * @ORM\Column(name="dt_exp", type="datetime", nullable=true) |
||
| 174 | */ |
||
| 175 | private $dtExp; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var \DateTime |
||
| 179 | * |
||
| 180 | * @ORM\Column(name="dt_gruen", type="datetime", nullable=true) |
||
| 181 | */ |
||
| 182 | private $dtGruen; |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @var \DateTime |
||
| 186 | * |
||
| 187 | * @ORM\Column(name="dt_backup", type="datetime", nullable=true) |
||
| 188 | */ |
||
| 189 | private $dtBackup; |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $donorFullName |
||
| 193 | * |
||
| 194 | * @return DoctrineDonation |
||
| 195 | */ |
||
| 196 | public function setDonorFullName( $donorFullName ) { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | public function getDonorFullName() { |
||
| 208 | |||
| 209 | /** |
||
| 210 | * @param string $donorCity |
||
| 211 | * |
||
| 212 | * @return DoctrineDonation |
||
| 213 | */ |
||
| 214 | public function setDonorCity( $donorCity ) { |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | public function getDonorCity() { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @param string $donorEmail |
||
| 229 | * |
||
| 230 | * @return DoctrineDonation |
||
| 231 | */ |
||
| 232 | public function setDonorEmail( $donorEmail ) { |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @return string |
||
| 240 | */ |
||
| 241 | public function getDonorEmail() { |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @param boolean $donorOptsIntoNewsletter |
||
| 247 | * |
||
| 248 | * @return DoctrineDonation |
||
| 249 | */ |
||
| 250 | public function setDonorOptsIntoNewsletter( $donorOptsIntoNewsletter ) { |
||
| 255 | |||
| 256 | /** |
||
| 257 | * @return boolean |
||
| 258 | */ |
||
| 259 | public function getDonorOptsIntoNewsletter() { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Set donation receipt state |
||
| 265 | * |
||
| 266 | * @param boolean $donationReceipt |
||
| 267 | * |
||
| 268 | *@return DoctrineDonation |
||
| 269 | */ |
||
| 270 | public function setDonationReceipt( $donationReceipt ) { |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Get donation receipt state |
||
| 278 | * |
||
| 279 | * @return boolean |
||
| 280 | */ |
||
| 281 | public function getDonationReceipt() { |
||
| 284 | |||
| 285 | /** |
||
| 286 | * Set publicly displayed donation record |
||
| 287 | * |
||
| 288 | * @param string $publicRecord |
||
| 289 | * |
||
| 290 | *@return DoctrineDonation |
||
| 291 | */ |
||
| 292 | public function setPublicRecord( $publicRecord ) { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Get publicly displayed donation record |
||
| 300 | * |
||
| 301 | * @return string |
||
| 302 | */ |
||
| 303 | public function getPublicRecord() { |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @param string $amount |
||
| 309 | * |
||
| 310 | *@return DoctrineDonation |
||
| 311 | */ |
||
| 312 | public function setAmount( $amount ) { |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @return string |
||
| 320 | */ |
||
| 321 | public function getAmount() { |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param integer $paymentIntervalInMonths |
||
| 327 | * |
||
| 328 | * @return DoctrineDonation |
||
| 329 | */ |
||
| 330 | public function setPaymentIntervalInMonths( $paymentIntervalInMonths ) { |
||
| 335 | |||
| 336 | /** |
||
| 337 | * @return integer |
||
| 338 | */ |
||
| 339 | public function getPaymentIntervalInMonths() { |
||
| 342 | |||
| 343 | /** |
||
| 344 | * Set payment type short code |
||
| 345 | * |
||
| 346 | * @param string $paymentType |
||
| 347 | * |
||
| 348 | *@return DoctrineDonation |
||
| 349 | */ |
||
| 350 | public function setPaymentType( $paymentType ) { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Get payment type short code |
||
| 358 | * |
||
| 359 | * @return string |
||
| 360 | */ |
||
| 361 | public function getPaymentType() { |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @param string $comment |
||
| 367 | * |
||
| 368 | * @return DoctrineDonation |
||
| 369 | */ |
||
| 370 | public function setComment( $comment ) { |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @return string |
||
| 378 | */ |
||
| 379 | public function getComment() { |
||
| 382 | |||
| 383 | /** |
||
| 384 | * Set bank transfer reference code |
||
| 385 | * |
||
| 386 | * @param string $bankTransferCode |
||
| 387 | * |
||
| 388 | * @return DoctrineDonation |
||
| 389 | */ |
||
| 390 | public function setBankTransferCode( $bankTransferCode ) { |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Get bank transfer reference code |
||
| 398 | * |
||
| 399 | * @return string |
||
| 400 | */ |
||
| 401 | public function getBankTransferCode() { |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @param string $source |
||
| 407 | * |
||
| 408 | * @return DoctrineDonation |
||
| 409 | */ |
||
| 410 | public function setSource( $source ) { |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @return string |
||
| 418 | */ |
||
| 419 | public function getSource() { |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @param string $remoteAddr |
||
| 425 | * |
||
| 426 | * @return DoctrineDonation |
||
| 427 | */ |
||
| 428 | public function setRemoteAddr( $remoteAddr ) { |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @return string |
||
| 436 | */ |
||
| 437 | public function getRemoteAddr() { |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @param string $hash |
||
| 443 | * |
||
| 444 | * @return DoctrineDonation |
||
| 445 | */ |
||
| 446 | public function setHash( $hash ) { |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @return string |
||
| 454 | */ |
||
| 455 | public function getHash() { |
||
| 458 | |||
| 459 | /** |
||
| 460 | * Sets if the donations comment should be public or private. |
||
| 461 | * |
||
| 462 | *@param boolean $isPublic |
||
| 463 | * |
||
| 464 | * @return DoctrineDonation |
||
| 465 | */ |
||
| 466 | public function setIsPublic( $isPublic ) { |
||
| 471 | |||
| 472 | /** |
||
| 473 | * Gets if the donations comment is public or private. |
||
| 474 | * @return boolean |
||
| 475 | */ |
||
| 476 | public function getIsPublic() { |
||
| 479 | |||
| 480 | /** |
||
| 481 | * @param \DateTime $creationTime |
||
| 482 | * |
||
| 483 | * @return DoctrineDonation |
||
| 484 | */ |
||
| 485 | public function setCreationTime( $creationTime ) { |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @return \DateTime |
||
| 493 | */ |
||
| 494 | public function getCreationTime() { |
||
| 497 | |||
| 498 | /** |
||
| 499 | * @param \DateTime|null $deletionTime |
||
| 500 | * |
||
| 501 | * @return DoctrineDonation |
||
| 502 | */ |
||
| 503 | public function setDeletionTime( $deletionTime ) { |
||
| 508 | |||
| 509 | /** |
||
| 510 | * @return \DateTime|null |
||
| 511 | */ |
||
| 512 | public function getDeletionTime() { |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @param \DateTime $dtExp |
||
| 518 | * |
||
| 519 | * @return DoctrineDonation |
||
| 520 | */ |
||
| 521 | public function setDtExp( $dtExp ) { |
||
| 526 | |||
| 527 | /** |
||
| 528 | * @return \DateTime |
||
| 529 | */ |
||
| 530 | public function getDtExp() { |
||
| 533 | |||
| 534 | /** |
||
| 535 | * @param string $status |
||
| 536 | * |
||
| 537 | * @return DoctrineDonation |
||
| 538 | */ |
||
| 539 | public function setStatus( $status ) { |
||
| 544 | |||
| 545 | /** |
||
| 546 | * @return string |
||
| 547 | */ |
||
| 548 | public function getStatus() { |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @param \DateTime $dtGruen |
||
| 554 | * |
||
| 555 | *@return DoctrineDonation |
||
| 556 | */ |
||
| 557 | public function setDtGruen( $dtGruen ) { |
||
| 562 | |||
| 563 | /** |
||
| 564 | * @return \DateTime |
||
| 565 | */ |
||
| 566 | public function getDtGruen() { |
||
| 569 | |||
| 570 | /** |
||
| 571 | * @param \DateTime $dtBackup |
||
| 572 | * |
||
| 573 | *@return DoctrineDonation |
||
| 574 | */ |
||
| 575 | public function setDtBackup( $dtBackup ) { |
||
| 580 | |||
| 581 | /** |
||
| 582 | * @return \DateTime |
||
| 583 | */ |
||
| 584 | public function getDtBackup() { |
||
| 587 | |||
| 588 | /** |
||
| 589 | * @return integer|null |
||
| 590 | */ |
||
| 591 | public function getId() { |
||
| 594 | |||
| 595 | /** |
||
| 596 | * @since 2.0 |
||
| 597 | * |
||
| 598 | * @param integer|null $id |
||
| 599 | */ |
||
| 600 | public function setId( $id ) { |
||
| 603 | |||
| 604 | public function getUExpiry() { |
||
| 607 | |||
| 608 | public function uTokenIsExpired() { |
||
| 611 | |||
| 612 | public function validateToken( $tokenToCheck, $serverSecret ) { |
||
| 621 | |||
| 622 | public function getEntryType( $mode = null ) { |
||
| 644 | |||
| 645 | /** |
||
| 646 | * @deprecated since 2.0, use encodeAndSetData or setDataObject instead |
||
| 647 | * |
||
| 648 | * @param string $data Base 64 encoded, serialized PHP array |
||
| 649 | * |
||
| 650 | *@return DoctrineDonation |
||
| 651 | */ |
||
| 652 | public function setData( $data ) { |
||
| 657 | |||
| 658 | /** |
||
| 659 | * @deprecated since 2.0, use @see getDecodedData or @see getDataObject instead |
||
| 660 | * |
||
| 661 | * @return string Base 64 encoded, serialized PHP array |
||
| 662 | */ |
||
| 663 | public function getData() { |
||
| 666 | |||
| 667 | /** |
||
| 668 | * NOTE: if possible, use @see getDataObject instead, as it provides a nicer API. |
||
| 669 | * |
||
| 670 | * @since 2.0 |
||
| 671 | * @return array |
||
| 672 | */ |
||
| 673 | public function getDecodedData() { |
||
| 678 | |||
| 679 | /** |
||
| 680 | * NOTE: if possible, use @see modifyDataObject instead, as it provides a nicer API. |
||
| 681 | * |
||
| 682 | * @since 2.0 |
||
| 683 | * @param array $data |
||
| 684 | */ |
||
| 685 | public function encodeAndSetData( array $data ) { |
||
| 688 | |||
| 689 | /** |
||
| 690 | * WARNING: updates made to the return value will not be reflected in the Donation state. |
||
| 691 | * Similarly, updates to the Donation state will not propagate to the returned object. |
||
| 692 | * To update the Donation state, explicitly call @see setDataObject. |
||
| 693 | * |
||
| 694 | * @since 2.0 |
||
| 695 | * @return DonationData |
||
| 696 | */ |
||
| 697 | public function getDataObject() { |
||
| 708 | |||
| 709 | /** |
||
| 710 | * @since 2.0 |
||
| 711 | * @param DonationData $data |
||
| 712 | */ |
||
| 713 | public function setDataObject( DonationData $data ) { |
||
| 731 | |||
| 732 | /** |
||
| 733 | * @since 2.0 |
||
| 734 | * @param callable $modificationFunction Takes a modifiable DonationData parameter |
||
| 735 | */ |
||
| 736 | public function modifyDataObject( callable $modificationFunction ) { |
||
| 741 | |||
| 742 | } |
||
| 743 |