Complex classes like SubscriptionTrait 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 SubscriptionTrait, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | trait SubscriptionTrait |
||
| 11 | { |
||
| 12 | |||
| 13 | /** |
||
| 14 | * The subscription ID. |
||
| 15 | * |
||
| 16 | * @var integer |
||
| 17 | * |
||
| 18 | * @JMS\Type("integer") |
||
| 19 | * @JMS\SerializedName("SUBSCRIPTION_ID") |
||
| 20 | */ |
||
| 21 | protected $subscriptionId; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The customer ID. |
||
| 25 | * |
||
| 26 | * @var integer |
||
| 27 | * |
||
| 28 | * @JMS\Type("integer") |
||
| 29 | * @JMS\SerializedName("CUSTOMER_ID") |
||
| 30 | */ |
||
| 31 | protected $customerId; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The subscription title. |
||
| 35 | * |
||
| 36 | * @var string |
||
| 37 | * |
||
| 38 | * @JMS\Type("string") |
||
| 39 | * @JMS\SerializedName("SUBSCRIPTION_TITLE") |
||
| 40 | */ |
||
| 41 | protected $subscriptionTitle; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The subscription start. |
||
| 45 | * |
||
| 46 | * @var \DateTime |
||
| 47 | * |
||
| 48 | * @JMS\Type("DateTime<'Y-m-d H:i:s'>") |
||
| 49 | * @JMS\SerializedName("START") |
||
| 50 | */ |
||
| 51 | protected $subscriptionStart; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * The subscription next event. |
||
| 55 | * |
||
| 56 | * @var \DateTime |
||
| 57 | * |
||
| 58 | * @JMS\Type("DateTime<'Y-m-d H:i:s'>") |
||
| 59 | * @JMS\SerializedName("NEXT_EVENT") |
||
| 60 | */ |
||
| 61 | protected $nextEvent; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * The subscription cancellation date. |
||
| 65 | * |
||
| 66 | * @var \DateTime |
||
| 67 | * |
||
| 68 | * @JMS\Type("DateTime<'Y-m-d H:i:s'>") |
||
| 69 | * @JMS\SerializedName("CANCELLATION_DATE") |
||
| 70 | */ |
||
| 71 | protected $cancellationDate; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The subscription status. |
||
| 75 | * |
||
| 76 | * @var string |
||
| 77 | * |
||
| 78 | * @JMS\Type("string") |
||
| 79 | * @JMS\SerializedName("STATUS") |
||
| 80 | */ |
||
| 81 | protected $status; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * The subscription hash. |
||
| 85 | * |
||
| 86 | * @var string |
||
| 87 | * |
||
| 88 | * @JMS\Type("string") |
||
| 89 | * @JMS\SerializedName("HASH") |
||
| 90 | */ |
||
| 91 | protected $hash; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * The subscription X-Attribute. |
||
| 95 | * |
||
| 96 | * @var array |
||
| 97 | * |
||
| 98 | * @JMS\Type("array") |
||
| 99 | * @JMS\SerializedName("X_ATTRIBUTES") |
||
| 100 | */ |
||
| 101 | protected $xAttributes = array(); |
||
| 102 | |||
| 103 | /** |
||
| 104 | * The subscription article number. |
||
| 105 | * |
||
| 106 | * @var string |
||
| 107 | * |
||
| 108 | * @JMS\Type("string") |
||
| 109 | * @JMS\SerializedName("ARTICLE_NUMBER") |
||
| 110 | */ |
||
| 111 | protected $articleNumber; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * The subscription quantity. |
||
| 115 | * |
||
| 116 | * @var integer |
||
| 117 | * |
||
| 118 | * @JMS\Type("integer") |
||
| 119 | * @JMS\SerializedName("QUANTITY") |
||
| 120 | */ |
||
| 121 | protected $quantity; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var SubscriptionPlanObject |
||
| 125 | * |
||
| 126 | * @JMS\Type("Speicher210\Fastbill\Api\Model\SubscriptionPlanObject") |
||
| 127 | * @JMS\SerializedName("PLAN") |
||
| 128 | */ |
||
| 129 | protected $plan; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * The external subscription ID. |
||
| 133 | * |
||
| 134 | * @var string |
||
| 135 | * |
||
| 136 | * @JMS\Type("string") |
||
| 137 | * @JMS\SerializedName("SUBSCRIPTION_EXT_UID") |
||
| 138 | */ |
||
| 139 | protected $subscriptionExternalId; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * The invoice title. |
||
| 143 | * |
||
| 144 | * @var string |
||
| 145 | * |
||
| 146 | * @JMS\Type("string") |
||
| 147 | * @JMS\SerializedName("INVOICE_TITLE") |
||
| 148 | */ |
||
| 149 | protected $invoiceTitle; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * The coupon applied to the subscription. |
||
| 153 | * |
||
| 154 | * @var Coupon |
||
| 155 | * |
||
| 156 | * @JMS\Type("Speicher210\Fastbill\Api\Model\Coupon") |
||
| 157 | * @JMS\SerializedName("COUPON") |
||
| 158 | */ |
||
| 159 | protected $coupon; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * The last event date and time. |
||
| 163 | * |
||
| 164 | * @var \DateTime |
||
| 165 | * |
||
| 166 | * @JMS\Type("DateTime<'Y-m-d H:i:s'>") |
||
| 167 | * @JMS\SerializedName("LAST_EVENT") |
||
| 168 | */ |
||
| 169 | protected $lastEvent; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * The reason for cancellation of a subscription. |
||
| 173 | * |
||
| 174 | * @var string |
||
| 175 | * |
||
| 176 | * @JMS\Type("string") |
||
| 177 | * @JMS\SerializedName("CANCELLATION_NOTE") |
||
| 178 | */ |
||
| 179 | protected $cancellationNote; |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @var array |
||
| 183 | * |
||
| 184 | * @JMS\Type("array") |
||
| 185 | * @JMS\SerializedName("ADDONS") |
||
| 186 | */ |
||
| 187 | protected $addons; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Date and time when the subscription expires. |
||
| 191 | * |
||
| 192 | * @var \DateTime |
||
| 193 | * |
||
| 194 | * @JMS\Type("DateTime<'Y-m-d H:i:s'>") |
||
| 195 | * @JMS\SerializedName("EXPIRATION_DATE") |
||
| 196 | */ |
||
| 197 | protected $expirationDate; |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @var SubscriptionPlanObject |
||
| 201 | * |
||
| 202 | 3 | * @JMS\Type("Speicher210\Fastbill\Api\Model\SubscriptionPlanObject") |
|
| 203 | * @JMS\SerializedName("PLAN_UPCOMING") |
||
| 204 | 3 | */ |
|
| 205 | protected $planUpcoming; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Get the subscription ID. |
||
| 209 | * |
||
| 210 | * @return integer |
||
| 211 | */ |
||
| 212 | public function getSubscriptionId() |
||
| 216 | |||
| 217 | 9 | /** |
|
| 218 | * Set the subscription ID. |
||
| 219 | * |
||
| 220 | * @param integer $subscriptionId The subscription ID. |
||
| 221 | * @return $this |
||
| 222 | */ |
||
| 223 | public function setSubscriptionId($subscriptionId) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Get the customer ID. |
||
| 232 | * |
||
| 233 | * @return integer |
||
| 234 | */ |
||
| 235 | public function getCustomerId() |
||
| 239 | |||
| 240 | 15 | /** |
|
| 241 | * Set the customer ID. |
||
| 242 | * |
||
| 243 | * @param integer $customerId The ID of the customer. |
||
| 244 | * @return $this |
||
| 245 | */ |
||
| 246 | public function setCustomerId($customerId) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Get the external subscription ID. |
||
| 255 | * |
||
| 256 | * @return string |
||
| 257 | */ |
||
| 258 | public function getSubscriptionExternalId() |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Set the external subscription ID. |
||
| 265 | * |
||
| 266 | * @param string $subscriptionExternalId The external subscription ID. |
||
| 267 | * @return $this |
||
| 268 | */ |
||
| 269 | public function setSubscriptionExternalId($subscriptionExternalId) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * Get the subscription title. |
||
| 278 | * |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | public function getSubscriptionTitle() |
||
| 285 | |||
| 286 | 6 | /** |
|
| 287 | * Set the subscription title. |
||
| 288 | * |
||
| 289 | * @param string $subscriptionTitle The title. |
||
| 290 | * @return $this |
||
| 291 | */ |
||
| 292 | public function setSubscriptionTitle($subscriptionTitle) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Get the subscription start. |
||
| 301 | * |
||
| 302 | * @return \DateTime |
||
| 303 | */ |
||
| 304 | public function getSubscriptionStart() |
||
| 308 | |||
| 309 | 6 | /** |
|
| 310 | * Set the subscription start. |
||
| 311 | * |
||
| 312 | * @param \DateTime $subscriptionStart |
||
| 313 | * @return $this |
||
| 314 | */ |
||
| 315 | public function setSubscriptionStart($subscriptionStart) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * @return \DateTime |
||
| 324 | 6 | */ |
|
| 325 | public function getNextEvent() |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @param \DateTime $nextEvent |
||
| 332 | * @return $this |
||
| 333 | */ |
||
| 334 | public function setNextEvent($nextEvent) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Get the cancellation date and time. |
||
| 343 | * |
||
| 344 | * @return \DateTime |
||
| 345 | */ |
||
| 346 | public function getCancellationDate() |
||
| 350 | |||
| 351 | 9 | /** |
|
| 352 | * Set the cancellation date and time. |
||
| 353 | * |
||
| 354 | * @param \DateTime $cancellationDate The cancellation date and time. |
||
| 355 | * @return $this |
||
| 356 | */ |
||
| 357 | public function setCancellationDate($cancellationDate) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Get the subscription status. |
||
| 366 | * |
||
| 367 | * @return string |
||
| 368 | */ |
||
| 369 | public function getStatus() |
||
| 373 | |||
| 374 | 18 | /** |
|
| 375 | * Set the subscription status. |
||
| 376 | * |
||
| 377 | * @param string $status The subscription status. |
||
| 378 | * @return $this |
||
| 379 | */ |
||
| 380 | public function setStatus($status) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Get the hash. |
||
| 389 | * |
||
| 390 | * @return string |
||
| 391 | */ |
||
| 392 | public function getHash() |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Set the hash. |
||
| 399 | * |
||
| 400 | * @param string $hash The hash. |
||
| 401 | * @return $this |
||
| 402 | */ |
||
| 403 | public function setHash($hash) |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @return array |
||
| 412 | */ |
||
| 413 | public function getXAttributes() |
||
| 417 | |||
| 418 | /** |
||
| 419 | * @param array $xAttributes |
||
| 420 | * @return $this |
||
| 421 | */ |
||
| 422 | public function setXAttributes(array $xAttributes) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @return int |
||
| 431 | */ |
||
| 432 | public function getArticleNumber() |
||
| 436 | |||
| 437 | 9 | /** |
|
| 438 | * Set the article number. |
||
| 439 | * |
||
| 440 | * @param string $articleNumber The article number. |
||
| 441 | * @return $this |
||
| 442 | */ |
||
| 443 | public function setArticleNumber($articleNumber) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @return integer |
||
| 452 | */ |
||
| 453 | public function getQuantity() |
||
| 457 | |||
| 458 | /** |
||
| 459 | * Set the quantity. |
||
| 460 | * |
||
| 461 | * @param integer $quantity The quantity. |
||
| 462 | * @return $this |
||
| 463 | */ |
||
| 464 | public function setQuantity($quantity) |
||
| 470 | |||
| 471 | /** |
||
| 472 | * Get the plan. |
||
| 473 | * |
||
| 474 | * @return SubscriptionPlanObject |
||
| 475 | */ |
||
| 476 | public function getPlan() |
||
| 480 | |||
| 481 | /** |
||
| 482 | * Set the plan. |
||
| 483 | * |
||
| 484 | * @param SubscriptionPlanObject $plan The plan. |
||
| 485 | * @return $this |
||
| 486 | */ |
||
| 487 | public function setPlan($plan) |
||
| 493 | |||
| 494 | /** |
||
| 495 | * @return string |
||
| 496 | */ |
||
| 497 | public function getInvoiceTitle() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @param string $invoiceTitle |
||
| 504 | * @return $this |
||
| 505 | */ |
||
| 506 | public function setInvoiceTitle($invoiceTitle) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Get the coupon for the subscription. |
||
| 515 | * |
||
| 516 | * @return Coupon |
||
| 517 | */ |
||
| 518 | public function getCoupon() |
||
| 522 | |||
| 523 | /** |
||
| 524 | * Set the coupon. |
||
| 525 | * |
||
| 526 | * @param Coupon $coupon The coupon to set. |
||
| 527 | */ |
||
| 528 | public function setCoupon(Coupon $coupon) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @return mixed |
||
| 535 | */ |
||
| 536 | public function getLastEvent() |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @param mixed $lastEvent |
||
| 543 | * @return $this |
||
| 544 | */ |
||
| 545 | public function setLastEvent($lastEvent) |
||
| 551 | |||
| 552 | /** |
||
| 553 | * @return array |
||
| 554 | */ |
||
| 555 | public function getAddons() |
||
| 559 | |||
| 560 | /** |
||
| 561 | * @param array $addons |
||
| 562 | * @return $this |
||
| 563 | */ |
||
| 564 | public function setAddons($addons) |
||
| 570 | |||
| 571 | /** |
||
| 572 | * @return \DateTime |
||
| 573 | */ |
||
| 574 | public function getExpirationDate() |
||
| 578 | |||
| 579 | /** |
||
| 580 | * @param \DateTime $expirationDate |
||
| 581 | * @return $this |
||
| 582 | */ |
||
| 583 | public function setExpirationDate($expirationDate) |
||
| 589 | |||
| 590 | /** |
||
| 591 | * @return SubscriptionPlanObject |
||
| 592 | */ |
||
| 593 | public function getPlanUpcoming() |
||
| 597 | |||
| 598 | /** |
||
| 599 | * @param SubscriptionPlanObject $planUpcoming |
||
| 600 | * @return $this |
||
| 601 | */ |
||
| 602 | public function setPlanUpcoming($planUpcoming) |
||
| 608 | |||
| 609 | /** |
||
| 610 | * Get the cancellation note. |
||
| 611 | * |
||
| 612 | * @return string |
||
| 613 | */ |
||
| 614 | public function getCancellationNote() |
||
| 618 | |||
| 619 | /** |
||
| 620 | * Set the cancellation note. |
||
| 621 | * |
||
| 622 | * @param string $cancellationNote The cancellation note. |
||
| 623 | * @return $this |
||
| 624 | */ |
||
| 625 | public function setCancellationNote($cancellationNote) |
||
| 631 | } |
||
| 632 |