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 |
||
| 14 | class Donation { |
||
| 15 | /** |
||
| 16 | * @var string |
||
| 17 | * |
||
| 18 | * @ORM\Column(name="name", type="string", length=250, nullable=true) |
||
| 19 | */ |
||
| 20 | private $name; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | * |
||
| 25 | * @ORM\Column(name="ort", type="string", length=250, nullable=true) |
||
| 26 | */ |
||
| 27 | private $city; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | * |
||
| 32 | * @ORM\Column(name="email", type="string", length=250, nullable=true) |
||
| 33 | */ |
||
| 34 | private $email; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var boolean |
||
| 38 | * |
||
| 39 | * @ORM\Column(name="info", type="boolean", options={"default":0}, nullable=false) |
||
| 40 | */ |
||
| 41 | private $info = 0; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var boolean |
||
| 45 | * |
||
| 46 | * @ORM\Column(name="bescheinigung", type="boolean", nullable=true) |
||
| 47 | */ |
||
| 48 | private $donationReceipt; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var string |
||
| 52 | * |
||
| 53 | * @ORM\Column(name="eintrag", type="string", length=250, options={"default":""}, nullable=false) |
||
| 54 | */ |
||
| 55 | private $publicRecord = ''; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | * |
||
| 60 | * @ORM\Column(name="betrag", type="string", length=250, nullable=true) |
||
| 61 | */ |
||
| 62 | private $amount; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var integer |
||
| 66 | * |
||
| 67 | * @ORM\Column(name="periode", type="smallint", options={"default":0}, nullable=false) |
||
| 68 | */ |
||
| 69 | private $period = 0; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string |
||
| 73 | * |
||
| 74 | * @ORM\Column(name="zahlweise", type="string", length=3, options={"default":"BEZ", "fixed":true}, nullable=false) |
||
| 75 | */ |
||
| 76 | private $paymentType = 'BEZ'; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var string |
||
| 80 | * |
||
| 81 | * @ORM\Column(name="kommentar", type="text", options={"default":""}, nullable=false) |
||
| 82 | */ |
||
| 83 | private $comment = ''; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var string |
||
| 87 | * |
||
| 88 | * @ORM\Column(name="ueb_code", type="string", length=32, options={"default":""}, nullable=false) |
||
| 89 | */ |
||
| 90 | private $transferCode = ''; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @var string |
||
| 94 | * |
||
| 95 | * @ORM\Column(name="data", type="text", nullable=true) |
||
| 96 | */ |
||
| 97 | private $data; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | * |
||
| 102 | * @ORM\Column(name="source", type="string", length=250, nullable=true) |
||
| 103 | */ |
||
| 104 | private $source; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @var string |
||
| 108 | * |
||
| 109 | * @ORM\Column(name="remote_addr", type="string", length=250, options={"default":""}, nullable=false) |
||
| 110 | */ |
||
| 111 | private $remoteAddr = ''; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @var string |
||
| 115 | * |
||
| 116 | * @ORM\Column(name="hash", type="string", length=250, nullable=true) |
||
| 117 | */ |
||
| 118 | private $hash; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @var boolean |
||
| 122 | * |
||
| 123 | * @ORM\Column(name="is_public", type="boolean", options={"default":0}, nullable=false) |
||
| 124 | */ |
||
| 125 | private $isPublic = 0; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @var \DateTime |
||
| 129 | * |
||
| 130 | * @Gedmo\Timestampable(on="create") |
||
| 131 | * @ORM\Column(name="dt_new", type="datetime", nullable=true) |
||
| 132 | */ |
||
| 133 | private $dtNew; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @var \DateTime |
||
| 137 | * |
||
| 138 | * @ORM\Column(name="dt_del", type="datetime", nullable=true) |
||
| 139 | */ |
||
| 140 | private $dtDel; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @var \DateTime |
||
| 144 | * |
||
| 145 | * @ORM\Column(name="dt_exp", type="datetime", nullable=true) |
||
| 146 | */ |
||
| 147 | private $dtExp; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @var \DateTime |
||
| 151 | * |
||
| 152 | * @Gedmo\Timestampable(on="update") |
||
| 153 | * @ORM\Column(name="updatedAt", type="datetime", nullable=true) |
||
| 154 | */ |
||
| 155 | private $updatedAt; |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @var string |
||
| 159 | * |
||
| 160 | * @ORM\Column(name="status", type="string", length=1, options={"default":"N", "fixed":true}, nullable=false) |
||
| 161 | */ |
||
| 162 | private $status = 'N'; |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @var \DateTime |
||
| 166 | * |
||
| 167 | * @ORM\Column(name="dt_gruen", type="datetime", nullable=true) |
||
| 168 | */ |
||
| 169 | private $dtGruen; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var \DateTime |
||
| 173 | * |
||
| 174 | * @ORM\Column(name="dt_backup", type="datetime", nullable=true) |
||
| 175 | */ |
||
| 176 | private $dtBackup; |
||
| 177 | |||
| 178 | /** |
||
| 179 | * @var integer |
||
| 180 | * |
||
| 181 | * @ORM\Column(name="id", type="integer") |
||
| 182 | * @ORM\Id |
||
| 183 | * @ORM\GeneratedValue(strategy="IDENTITY") |
||
| 184 | */ |
||
| 185 | private $id; |
||
| 186 | |||
| 187 | |||
| 188 | /** |
||
| 189 | * Set name |
||
| 190 | * |
||
| 191 | * @param string $name |
||
| 192 | * @return self |
||
| 193 | */ |
||
| 194 | public function setName( $name ) { |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Get name |
||
| 202 | * |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | public function getName() { |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Set city |
||
| 211 | * |
||
| 212 | * @param string $city |
||
| 213 | * @return self |
||
| 214 | */ |
||
| 215 | public function setCity( $city ) { |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Get city |
||
| 223 | * |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | public function getCity() { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Set email |
||
| 232 | * |
||
| 233 | * @param string $email |
||
| 234 | * @return self |
||
| 235 | */ |
||
| 236 | public function setEmail( $email ) { |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Get email |
||
| 244 | * |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | public function getEmail() { |
||
| 250 | |||
| 251 | /** |
||
| 252 | * Set info |
||
| 253 | * |
||
| 254 | * @param boolean $info |
||
| 255 | * @return self |
||
| 256 | */ |
||
| 257 | public function setInfo( $info ) { |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Get info |
||
| 265 | * |
||
| 266 | * @return boolean |
||
| 267 | */ |
||
| 268 | public function getInfo() { |
||
| 271 | |||
| 272 | /** |
||
| 273 | * Set donation receipt state |
||
| 274 | * |
||
| 275 | * @param boolean $donationReceipt |
||
| 276 | * @return self |
||
| 277 | */ |
||
| 278 | public function setDonationReceipt( $donationReceipt ) { |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Get donation receipt state |
||
| 286 | * |
||
| 287 | * @return boolean |
||
| 288 | */ |
||
| 289 | public function getDonationReceipt() { |
||
| 292 | |||
| 293 | /** |
||
| 294 | * Set publicly displayed donation record |
||
| 295 | * |
||
| 296 | * @param string $publicRecord |
||
| 297 | * @return self |
||
| 298 | */ |
||
| 299 | public function setPublicRecord( $publicRecord ) { |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Get publicly displayed donation record |
||
| 307 | * |
||
| 308 | * @return string |
||
| 309 | */ |
||
| 310 | public function getPublicRecord() { |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Set amount |
||
| 316 | * |
||
| 317 | * @param string $amount |
||
| 318 | * @return self |
||
| 319 | */ |
||
| 320 | public function setAmount( $amount ) { |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Get amount |
||
| 328 | * |
||
| 329 | * @return string |
||
| 330 | */ |
||
| 331 | public function getAmount() { |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Set period |
||
| 337 | * |
||
| 338 | * @param integer $period |
||
| 339 | * @return self |
||
| 340 | */ |
||
| 341 | public function setPeriod( $period ) { |
||
| 346 | |||
| 347 | /** |
||
| 348 | * Get period |
||
| 349 | * |
||
| 350 | * @return integer |
||
| 351 | */ |
||
| 352 | public function getPeriod() { |
||
| 355 | |||
| 356 | /** |
||
| 357 | * Set payment type short code |
||
| 358 | * |
||
| 359 | * @param string $paymentType |
||
| 360 | * @return self |
||
| 361 | */ |
||
| 362 | public function setPaymentType( $paymentType ) { |
||
| 367 | |||
| 368 | /** |
||
| 369 | * Get payment type short code |
||
| 370 | * |
||
| 371 | * @return string |
||
| 372 | */ |
||
| 373 | public function getPaymentType() { |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Set comment |
||
| 379 | * |
||
| 380 | * @param string $comment |
||
| 381 | * @return self |
||
| 382 | */ |
||
| 383 | public function setComment( $comment ) { |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Get comment |
||
| 391 | * |
||
| 392 | * @return string |
||
| 393 | */ |
||
| 394 | public function getComment() { |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Set bank transfer reference code |
||
| 400 | * |
||
| 401 | * @param string $transferCode |
||
| 402 | * @return self |
||
| 403 | */ |
||
| 404 | public function setTransferCode( $transferCode ) { |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Get bank transfer reference code |
||
| 412 | * |
||
| 413 | * @return string |
||
| 414 | */ |
||
| 415 | public function getTransferCode() { |
||
| 418 | |||
| 419 | /** |
||
| 420 | * Set data |
||
| 421 | * |
||
| 422 | * @param string $data |
||
| 423 | * @return self |
||
| 424 | */ |
||
| 425 | public function setData( $data ) { |
||
| 430 | |||
| 431 | /** |
||
| 432 | * Get data |
||
| 433 | * |
||
| 434 | * @return string |
||
| 435 | */ |
||
| 436 | public function getData() { |
||
| 439 | |||
| 440 | /** |
||
| 441 | * Set source |
||
| 442 | * |
||
| 443 | * @param string $source |
||
| 444 | * @return self |
||
| 445 | */ |
||
| 446 | public function setSource( $source ) { |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Get source |
||
| 454 | * |
||
| 455 | * @return string |
||
| 456 | */ |
||
| 457 | public function getSource() { |
||
| 460 | |||
| 461 | /** |
||
| 462 | * Set remoteAddr |
||
| 463 | * |
||
| 464 | * @param string $remoteAddr |
||
| 465 | * @return self |
||
| 466 | */ |
||
| 467 | public function setRemoteAddr( $remoteAddr ) { |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Get remoteAddr |
||
| 475 | * |
||
| 476 | * @return string |
||
| 477 | */ |
||
| 478 | public function getRemoteAddr() { |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Set hash |
||
| 484 | * |
||
| 485 | * @param string $hash |
||
| 486 | * @return self |
||
| 487 | */ |
||
| 488 | public function setHash( $hash ) { |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Get hash |
||
| 496 | * |
||
| 497 | * @return string |
||
| 498 | */ |
||
| 499 | public function getHash() { |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Set isPublic |
||
| 505 | * |
||
| 506 | * @param boolean $isPublic |
||
| 507 | * @return self |
||
| 508 | */ |
||
| 509 | public function setIsPublic( $isPublic ) { |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Get isPublic |
||
| 517 | * |
||
| 518 | * @return boolean |
||
| 519 | */ |
||
| 520 | public function getIsPublic() { |
||
| 523 | |||
| 524 | /** |
||
| 525 | * Set dtNew |
||
| 526 | * |
||
| 527 | * @param \DateTime $dtNew |
||
| 528 | * @return self |
||
| 529 | */ |
||
| 530 | public function setDtNew( $dtNew ) { |
||
| 535 | |||
| 536 | /** |
||
| 537 | * Get dtNew |
||
| 538 | * |
||
| 539 | * @return \DateTime |
||
| 540 | */ |
||
| 541 | public function getDtNew() { |
||
| 544 | |||
| 545 | /** |
||
| 546 | * Set dtDel |
||
| 547 | * |
||
| 548 | * @param \DateTime $dtDel |
||
| 549 | * @return self |
||
| 550 | */ |
||
| 551 | public function setDtDel( $dtDel ) { |
||
| 556 | |||
| 557 | /** |
||
| 558 | * Get dtDel |
||
| 559 | * |
||
| 560 | * @return \DateTime |
||
| 561 | */ |
||
| 562 | public function getDtDel() { |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Set dtExp |
||
| 568 | * |
||
| 569 | * @param \DateTime $dtExp |
||
| 570 | * @return self |
||
| 571 | */ |
||
| 572 | public function setDtExp( $dtExp ) { |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Get dtExp |
||
| 580 | * |
||
| 581 | * @return \DateTime |
||
| 582 | */ |
||
| 583 | public function getDtExp() { |
||
| 586 | |||
| 587 | /** |
||
| 588 | * Set status |
||
| 589 | * |
||
| 590 | * @param string $status |
||
| 591 | * @return self |
||
| 592 | */ |
||
| 593 | public function setStatus( $status ) { |
||
| 598 | |||
| 599 | /** |
||
| 600 | * Get status |
||
| 601 | * |
||
| 602 | * @return string |
||
| 603 | */ |
||
| 604 | public function getStatus() { |
||
| 607 | |||
| 608 | /** |
||
| 609 | * Set dtGruen |
||
| 610 | * |
||
| 611 | * @param \DateTime $dtGruen |
||
| 612 | * @return self |
||
| 613 | */ |
||
| 614 | public function setDtGruen( $dtGruen ) { |
||
| 619 | |||
| 620 | /** |
||
| 621 | * Get dtGruen |
||
| 622 | * |
||
| 623 | * @return \DateTime |
||
| 624 | */ |
||
| 625 | public function getDtGruen() { |
||
| 628 | |||
| 629 | /** |
||
| 630 | * Set dtBackup |
||
| 631 | * |
||
| 632 | * @param \DateTime $dtBackup |
||
| 633 | * @return self |
||
| 634 | */ |
||
| 635 | public function setDtBackup( $dtBackup ) { |
||
| 640 | |||
| 641 | /** |
||
| 642 | * Get dtBackup |
||
| 643 | * |
||
| 644 | * @return \DateTime |
||
| 645 | */ |
||
| 646 | public function getDtBackup() { |
||
| 649 | |||
| 650 | /** |
||
| 651 | * @return \DateTime |
||
| 652 | */ |
||
| 653 | public function getUpdatedAt() { |
||
| 656 | |||
| 657 | /** |
||
| 658 | * @param \DateTime $updatedAt |
||
| 659 | */ |
||
| 660 | public function setUpdatedAt( $updatedAt ) { |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Get id |
||
| 666 | * |
||
| 667 | * @return integer |
||
| 668 | */ |
||
| 669 | public function getId() { |
||
| 672 | |||
| 673 | public function getUExpiry() { |
||
| 678 | |||
| 679 | public function uTokenIsExpired() { |
||
| 683 | |||
| 684 | public function validateToken( $tokenToCheck, $serverSecret ) { |
||
| 693 | |||
| 694 | public function getEntryType( $mode = null ) { |
||
| 716 | |||
| 717 | private function decodeData( $data ) { |
||
| 720 | } |
||
| 721 |