Complex classes like Donation 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 Donation, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | class Donation { |
||
| 16 | /** |
||
| 17 | * @var string |
||
| 18 | * |
||
| 19 | * @ORM\Column(name="name", type="string", length=250, nullable=true) |
||
| 20 | */ |
||
| 21 | private $name; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | * |
||
| 26 | * @ORM\Column(name="ort", type="string", length=250, nullable=true) |
||
| 27 | */ |
||
| 28 | private $city; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string |
||
| 32 | * |
||
| 33 | * @ORM\Column(name="email", type="string", length=250, nullable=true) |
||
| 34 | */ |
||
| 35 | private $email; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var boolean |
||
| 39 | * |
||
| 40 | * @ORM\Column(name="info", type="boolean", options={"default":0}, nullable=false) |
||
| 41 | */ |
||
| 42 | private $info = 0; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var boolean |
||
| 46 | * |
||
| 47 | * @ORM\Column(name="bescheinigung", type="boolean", nullable=true) |
||
| 48 | */ |
||
| 49 | private $donationReceipt; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | * |
||
| 54 | * @ORM\Column(name="eintrag", type="string", length=250, options={"default":""}, nullable=false) |
||
| 55 | */ |
||
| 56 | private $publicRecord = ''; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | * |
||
| 61 | * @ORM\Column(name="betrag", type="string", length=250, nullable=true) |
||
| 62 | */ |
||
| 63 | private $amount; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @var integer |
||
| 67 | * |
||
| 68 | * @ORM\Column(name="periode", type="smallint", options={"default":0}, nullable=false) |
||
| 69 | */ |
||
| 70 | private $period = 0; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var string |
||
| 74 | * |
||
| 75 | * @ORM\Column(name="zahlweise", type="string", length=3, options={"default":"BEZ", "fixed":true}, nullable=false) |
||
| 76 | */ |
||
| 77 | private $paymentType = 'BEZ'; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | * |
||
| 82 | * @ORM\Column(name="kommentar", type="text", options={"default":""}, nullable=false) |
||
| 83 | */ |
||
| 84 | private $comment = ''; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var string |
||
| 88 | * |
||
| 89 | * @ORM\Column(name="ueb_code", type="string", length=32, options={"default":""}, nullable=false) |
||
| 90 | */ |
||
| 91 | private $transferCode = ''; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string |
||
| 95 | * |
||
| 96 | * @ORM\Column(name="data", type="text", nullable=true) |
||
| 97 | */ |
||
| 98 | private $data; |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @var string |
||
| 102 | * |
||
| 103 | * @ORM\Column(name="source", type="string", length=250, nullable=true) |
||
| 104 | */ |
||
| 105 | private $source; |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @var string |
||
| 109 | * |
||
| 110 | * @ORM\Column(name="remote_addr", type="string", length=250, options={"default":""}, nullable=false) |
||
| 111 | */ |
||
| 112 | private $remoteAddr = ''; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var string |
||
| 116 | * |
||
| 117 | * @ORM\Column(name="hash", type="string", length=250, nullable=true) |
||
| 118 | */ |
||
| 119 | private $hash; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @var boolean |
||
| 123 | * |
||
| 124 | * @ORM\Column(name="is_public", type="boolean", options={"default":0}, nullable=false) |
||
| 125 | */ |
||
| 126 | private $isPublic = 0; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @var \DateTime |
||
| 130 | * |
||
| 131 | * @Gedmo\Timestampable(on="create") |
||
| 132 | * @ORM\Column(name="dt_new", type="datetime") |
||
| 133 | */ |
||
| 134 | private $dtNew; |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @var \DateTime |
||
| 138 | * |
||
| 139 | * @ORM\Column(name="dt_del", type="datetime", nullable=true) |
||
| 140 | */ |
||
| 141 | private $dtDel; |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @var \DateTime |
||
| 145 | * |
||
| 146 | * @ORM\Column(name="dt_exp", type="datetime", nullable=true) |
||
| 147 | */ |
||
| 148 | private $dtExp; |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @var string |
||
| 152 | * |
||
| 153 | * @ORM\Column(name="status", type="string", length=1, options={"default":"N", "fixed":true}, nullable=false) |
||
| 154 | */ |
||
| 155 | private $status = 'N'; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var \DateTime |
||
| 159 | * |
||
| 160 | * @ORM\Column(name="dt_gruen", type="datetime", nullable=true) |
||
| 161 | */ |
||
| 162 | private $dtGruen; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var \DateTime |
||
| 166 | * |
||
| 167 | * @ORM\Column(name="dt_backup", type="datetime", nullable=true) |
||
| 168 | */ |
||
| 169 | private $dtBackup; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var integer |
||
| 173 | * |
||
| 174 | * @ORM\Column(name="id", type="integer") |
||
| 175 | * @ORM\Id |
||
| 176 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 177 | */ |
||
| 178 | private $id; |
||
| 179 | |||
| 180 | |||
| 181 | /** |
||
| 182 | * Set name |
||
| 183 | * |
||
| 184 | * @param string $name |
||
| 185 | * @return self |
||
| 186 | */ |
||
| 187 | public function setName( $name ) { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Get name |
||
| 195 | * |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | public function getName() { |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Set city |
||
| 204 | * |
||
| 205 | * @param string $city |
||
| 206 | * @return self |
||
| 207 | */ |
||
| 208 | public function setCity( $city ) { |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Get city |
||
| 216 | * |
||
| 217 | * @return string |
||
| 218 | */ |
||
| 219 | public function getCity() { |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Set email |
||
| 225 | * |
||
| 226 | * @param string $email |
||
| 227 | * @return self |
||
| 228 | */ |
||
| 229 | public function setEmail( $email ) { |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Get email |
||
| 237 | * |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | public function getEmail() { |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Set info |
||
| 246 | * |
||
| 247 | * @param boolean $info |
||
| 248 | * @return self |
||
| 249 | */ |
||
| 250 | public function setInfo( $info ) { |
||
| 255 | |||
| 256 | /** |
||
| 257 | * Get info |
||
| 258 | * |
||
| 259 | * @return boolean |
||
| 260 | */ |
||
| 261 | public function getInfo() { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * Set donation receipt state |
||
| 267 | * |
||
| 268 | * @param boolean $donationReceipt |
||
| 269 | * @return self |
||
| 270 | */ |
||
| 271 | public function setDonationReceipt( $donationReceipt ) { |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get donation receipt state |
||
| 279 | * |
||
| 280 | * @return boolean |
||
| 281 | */ |
||
| 282 | public function getDonationReceipt() { |
||
| 285 | |||
| 286 | /** |
||
| 287 | * Set publicly displayed donation record |
||
| 288 | * |
||
| 289 | * @param string $publicRecord |
||
| 290 | * @return self |
||
| 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 | * Set amount |
||
| 309 | * |
||
| 310 | * @param string $amount |
||
| 311 | * @return self |
||
| 312 | */ |
||
| 313 | public function setAmount( $amount ) { |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Get amount |
||
| 321 | * |
||
| 322 | * @return string |
||
| 323 | */ |
||
| 324 | public function getAmount() { |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Set period |
||
| 330 | * |
||
| 331 | * @param integer $period |
||
| 332 | * @return self |
||
| 333 | */ |
||
| 334 | public function setPeriod( $period ) { |
||
| 339 | |||
| 340 | /** |
||
| 341 | * Get period |
||
| 342 | * |
||
| 343 | * @return integer |
||
| 344 | */ |
||
| 345 | public function getPeriod() { |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Set payment type short code |
||
| 351 | * |
||
| 352 | * @param string $paymentType |
||
| 353 | * @return self |
||
| 354 | */ |
||
| 355 | public function setPaymentType( $paymentType ) { |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Get payment type short code |
||
| 363 | * |
||
| 364 | * @return string |
||
| 365 | */ |
||
| 366 | public function getPaymentType() { |
||
| 369 | |||
| 370 | /** |
||
| 371 | * Set comment |
||
| 372 | * |
||
| 373 | * @param string $comment |
||
| 374 | * @return self |
||
| 375 | */ |
||
| 376 | public function setComment( $comment ) { |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Get comment |
||
| 384 | * |
||
| 385 | * @return string |
||
| 386 | */ |
||
| 387 | public function getComment() { |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Set bank transfer reference code |
||
| 393 | * |
||
| 394 | * @param string $transferCode |
||
| 395 | * @return self |
||
| 396 | */ |
||
| 397 | public function setTransferCode( $transferCode ) { |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Get bank transfer reference code |
||
| 405 | * |
||
| 406 | * @return string |
||
| 407 | */ |
||
| 408 | public function getTransferCode() { |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Set source |
||
| 414 | * |
||
| 415 | * @param string $source |
||
| 416 | * @return self |
||
| 417 | */ |
||
| 418 | public function setSource( $source ) { |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Get source |
||
| 426 | * |
||
| 427 | * @return string |
||
| 428 | */ |
||
| 429 | public function getSource() { |
||
| 432 | |||
| 433 | /** |
||
| 434 | * Set remoteAddr |
||
| 435 | * |
||
| 436 | * @param string $remoteAddr |
||
| 437 | * @return self |
||
| 438 | */ |
||
| 439 | public function setRemoteAddr( $remoteAddr ) { |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Get remoteAddr |
||
| 447 | * |
||
| 448 | * @return string |
||
| 449 | */ |
||
| 450 | public function getRemoteAddr() { |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Set hash |
||
| 456 | * |
||
| 457 | * @param string $hash |
||
| 458 | * @return self |
||
| 459 | */ |
||
| 460 | public function setHash( $hash ) { |
||
| 465 | |||
| 466 | /** |
||
| 467 | * Get hash |
||
| 468 | * |
||
| 469 | * @return string |
||
| 470 | */ |
||
| 471 | public function getHash() { |
||
| 474 | |||
| 475 | /** |
||
| 476 | * Set isPublic |
||
| 477 | * |
||
| 478 | * @param boolean $isPublic |
||
| 479 | * @return self |
||
| 480 | */ |
||
| 481 | public function setIsPublic( $isPublic ) { |
||
| 486 | |||
| 487 | /** |
||
| 488 | * Get isPublic |
||
| 489 | * |
||
| 490 | * @return boolean |
||
| 491 | */ |
||
| 492 | public function getIsPublic() { |
||
| 495 | |||
| 496 | /** |
||
| 497 | * Set dtNew |
||
| 498 | * |
||
| 499 | * @param \DateTime $dtNew |
||
| 500 | * @return self |
||
| 501 | */ |
||
| 502 | public function setDtNew( $dtNew ) { |
||
| 507 | |||
| 508 | /** |
||
| 509 | * Get dtNew |
||
| 510 | * |
||
| 511 | * @return \DateTime |
||
| 512 | */ |
||
| 513 | public function getDtNew() { |
||
| 516 | |||
| 517 | /** |
||
| 518 | * Set dtDel |
||
| 519 | * |
||
| 520 | * @param \DateTime|null $dtDel |
||
| 521 | * @return self |
||
| 522 | */ |
||
| 523 | public function setDtDel( $dtDel ) { |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Get dtDel |
||
| 531 | * |
||
| 532 | * @return \DateTime|null |
||
| 533 | */ |
||
| 534 | public function getDtDel() { |
||
| 537 | |||
| 538 | /** |
||
| 539 | * Set dtExp |
||
| 540 | * |
||
| 541 | * @param \DateTime $dtExp |
||
| 542 | * @return self |
||
| 543 | */ |
||
| 544 | public function setDtExp( $dtExp ) { |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Get dtExp |
||
| 552 | * |
||
| 553 | * @return \DateTime |
||
| 554 | */ |
||
| 555 | public function getDtExp() { |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Set status |
||
| 561 | * |
||
| 562 | * @param string $status |
||
| 563 | * @return self |
||
| 564 | */ |
||
| 565 | public function setStatus( $status ) { |
||
| 570 | |||
| 571 | /** |
||
| 572 | * Get status |
||
| 573 | * |
||
| 574 | * @return string |
||
| 575 | */ |
||
| 576 | public function getStatus() { |
||
| 579 | |||
| 580 | /** |
||
| 581 | * Set dtGruen |
||
| 582 | * |
||
| 583 | * @param \DateTime $dtGruen |
||
| 584 | * @return self |
||
| 585 | */ |
||
| 586 | public function setDtGruen( $dtGruen ) { |
||
| 591 | |||
| 592 | /** |
||
| 593 | * Get dtGruen |
||
| 594 | * |
||
| 595 | * @return \DateTime |
||
| 596 | */ |
||
| 597 | public function getDtGruen() { |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Set dtBackup |
||
| 603 | * |
||
| 604 | * @param \DateTime $dtBackup |
||
| 605 | * @return self |
||
| 606 | */ |
||
| 607 | public function setDtBackup( $dtBackup ) { |
||
| 612 | |||
| 613 | /** |
||
| 614 | * Get dtBackup |
||
| 615 | * |
||
| 616 | * @return \DateTime |
||
| 617 | */ |
||
| 618 | public function getDtBackup() { |
||
| 621 | |||
| 622 | /** |
||
| 623 | * Get id |
||
| 624 | * |
||
| 625 | * @return integer|null |
||
| 626 | */ |
||
| 627 | public function getId() { |
||
| 630 | |||
| 631 | /** |
||
| 632 | * @since 2.0 |
||
| 633 | * |
||
| 634 | * @param integer|null $id |
||
| 635 | */ |
||
| 636 | public function setId( $id ) { |
||
| 639 | |||
| 640 | public function getUExpiry() { |
||
| 643 | |||
| 644 | public function uTokenIsExpired() { |
||
| 647 | |||
| 648 | public function validateToken( $tokenToCheck, $serverSecret ) { |
||
| 657 | |||
| 658 | public function getEntryType( $mode = null ) { |
||
| 680 | |||
| 681 | /** |
||
| 682 | * @deprecated since 2.0, use encodeAndSetData or setDataObject instead |
||
| 683 | * |
||
| 684 | * @param string $data Base 64 encoded, serialized PHP array |
||
| 685 | * @return self |
||
| 686 | */ |
||
| 687 | public function setData( $data ) { |
||
| 692 | |||
| 693 | /** |
||
| 694 | * @deprecated since 2.0, use @see getDecodedData or @see getDataObject instead |
||
| 695 | * |
||
| 696 | * @return string Base 64 encoded, serialized PHP array |
||
| 697 | */ |
||
| 698 | public function getData() { |
||
| 701 | |||
| 702 | /** |
||
| 703 | * NOTE: if possible, use @see getDataObject instead, as it provides a nicer API. |
||
| 704 | * |
||
| 705 | * @since 2.0 |
||
| 706 | * @return array |
||
| 707 | */ |
||
| 708 | public function getDecodedData() { |
||
| 713 | |||
| 714 | /** |
||
| 715 | * @since 2.0 |
||
| 716 | * @param array $data |
||
| 717 | */ |
||
| 718 | public function encodeAndSetData( array $data ) { |
||
| 721 | |||
| 722 | /** |
||
| 723 | * WARNING: updates made to the return value will not be reflected in the Donation state. |
||
| 724 | * Similarly, updates to the Donation state will not propagate to the returned object. |
||
| 725 | * To update the Donation state, explicitly call @see setDataObject. |
||
| 726 | * |
||
| 727 | * @since 2.0 |
||
| 728 | * @return DonationData |
||
| 729 | */ |
||
| 730 | public function getDataObject() { |
||
| 741 | |||
| 742 | /** |
||
| 743 | * @since 2.0 |
||
| 744 | * @param DonationData $data |
||
| 745 | */ |
||
| 746 | public function setDataObject( DonationData $data ) { |
||
| 764 | |||
| 765 | /** |
||
| 766 | * @since 2.0 |
||
| 767 | * @param callable $modificationFunction Takes a modifiable DonationData parameter |
||
| 768 | */ |
||
| 769 | public function modifyDataObject( callable $modificationFunction ) { |
||
| 774 | |||
| 775 | } |
||
| 776 |