Complex classes like Customer 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 Customer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | final class Customer implements CreatableFromArray |
||
| 10 | { |
||
| 11 | /** @var string|null */ |
||
| 12 | private $url; |
||
| 13 | /** @var string|null */ |
||
| 14 | private $address1; |
||
| 15 | /** @var string|null */ |
||
| 16 | private $address2; |
||
| 17 | /** @var string|null */ |
||
| 18 | private $city; |
||
| 19 | /** @var string|null */ |
||
| 20 | private $comments; |
||
| 21 | /** @var string|null */ |
||
| 22 | private $costCenter; |
||
| 23 | /** @var string|null */ |
||
| 24 | private $country; |
||
| 25 | /** @var string|null */ |
||
| 26 | private $countryCode; |
||
| 27 | /** @var string|null */ |
||
| 28 | private $currency; |
||
| 29 | /** @var string|null */ |
||
| 30 | private $customerNumber; |
||
| 31 | /** @var array */ |
||
| 32 | private $defaultDeliveryTypes; |
||
| 33 | /** @var array */ |
||
| 34 | private $defaultTemplates; |
||
| 35 | /** @var string|null */ |
||
| 36 | private $deliveryAddress1; |
||
| 37 | /** @var string|null */ |
||
| 38 | private $deliveryAddress2; |
||
| 39 | /** @var string|null */ |
||
| 40 | private $deliveryCity; |
||
| 41 | /** @var string|null */ |
||
| 42 | private $deliveryCountry; |
||
| 43 | /** @var string|null */ |
||
| 44 | private $deliveryCountryCode; |
||
| 45 | /** @var string|null */ |
||
| 46 | private $deliveryFax; |
||
| 47 | /** @var string|null */ |
||
| 48 | private $deliveryName; |
||
| 49 | /** @var string|null */ |
||
| 50 | private $deliveryPhone1; |
||
| 51 | /** @var string|null */ |
||
| 52 | private $deliveryPhone2; |
||
| 53 | /** @var string|null */ |
||
| 54 | private $deliveryZipCode; |
||
| 55 | /** @var string */ |
||
| 56 | private $email; |
||
| 57 | /** @var string */ |
||
| 58 | private $emailInvoice; |
||
| 59 | /** @var string */ |
||
| 60 | private $emailInvoiceBCC; |
||
| 61 | /** @var string */ |
||
| 62 | private $emailInvoiceCC; |
||
| 63 | /** @var string */ |
||
| 64 | private $emailOffer; |
||
| 65 | /** @var string */ |
||
| 66 | private $emailOfferBCC; |
||
| 67 | /** @var string */ |
||
| 68 | private $emailOfferCC; |
||
| 69 | /** @var string */ |
||
| 70 | private $emailOrder; |
||
| 71 | /** @var string */ |
||
| 72 | private $emailOrderBCC; |
||
| 73 | /** @var string */ |
||
| 74 | private $emailOrderCC; |
||
| 75 | /** @var string|null */ |
||
| 76 | private $fax; |
||
| 77 | /** @var string|null */ |
||
| 78 | private $invoiceAdministrationFee; |
||
| 79 | /** @var string|null */ |
||
| 80 | private $invoiceDiscount; |
||
| 81 | /** @var string|null */ |
||
| 82 | private $invoiceFreight; |
||
| 83 | /** @var string|null */ |
||
| 84 | private $invoiceRemark; |
||
| 85 | /** @var string|null */ |
||
| 86 | private $name; |
||
| 87 | /** @var string */ |
||
| 88 | private $organisationNumber; |
||
| 89 | /** @var string */ |
||
| 90 | private $ourReference; |
||
| 91 | /** @var string|null */ |
||
| 92 | private $phone1; |
||
| 93 | /** @var string|null */ |
||
| 94 | private $phone2; |
||
| 95 | /** @var string|null */ |
||
| 96 | private $priceList; |
||
| 97 | /** @var string|null */ |
||
| 98 | private $project; |
||
| 99 | /** @var string|null */ |
||
| 100 | private $salesAccount; |
||
| 101 | /** @var string|null */ |
||
| 102 | private $showPriceVATIncluded; |
||
| 103 | /** @var string */ |
||
| 104 | private $termsOfDelivery; |
||
| 105 | /** @var string */ |
||
| 106 | private $termsOfPayment; |
||
| 107 | /** @var string|null */ |
||
| 108 | private $type; |
||
| 109 | /** @var string */ |
||
| 110 | private $vatNumber; |
||
| 111 | /** @var string|null */ |
||
| 112 | private $vatType; |
||
| 113 | /** @var string|null */ |
||
| 114 | private $visitingAddress; |
||
| 115 | /** @var string|null */ |
||
| 116 | private $visitingCity; |
||
| 117 | /** @var string|null */ |
||
| 118 | private $visitingCountry; |
||
| 119 | /** @var string|null */ |
||
| 120 | private $visitingCountryCode; |
||
| 121 | /** @var string|null */ |
||
| 122 | private $visitingZipCode; |
||
| 123 | /** @var string */ |
||
| 124 | private $www; |
||
| 125 | /** @var string */ |
||
| 126 | private $wayOfDelivery; |
||
| 127 | /** @var string */ |
||
| 128 | private $yourReference; |
||
| 129 | /** @var string|null */ |
||
| 130 | private $zipCode; |
||
| 131 | |||
| 132 | 2 | private function __construct() |
|
| 135 | |||
| 136 | 2 | public static function createFromArray(array $data) |
|
| 203 | |||
| 204 | public function getUrl(): string |
||
| 208 | |||
| 209 | 1 | public function getAddress1(): string |
|
| 213 | |||
| 214 | public function getAddress2(): string |
||
| 218 | |||
| 219 | public function getCity(): string |
||
| 223 | |||
| 224 | public function getComments(): string |
||
| 228 | |||
| 229 | public function getCostCenter(): string |
||
| 233 | |||
| 234 | public function getCountry(): string |
||
| 238 | |||
| 239 | public function getCountryCode(): string |
||
| 243 | |||
| 244 | public function getCurrency(): string |
||
| 248 | |||
| 249 | public function getCustomerNumber(): string |
||
| 253 | |||
| 254 | public function getDefaultDeliveryTypes(): array |
||
| 258 | |||
| 259 | public function getDefaultTemplates(): array |
||
| 263 | |||
| 264 | public function getDeliveryAddress1(): string |
||
| 268 | |||
| 269 | public function getDeliveryAddress2(): string |
||
| 273 | |||
| 274 | public function getDeliveryCity(): string |
||
| 278 | |||
| 279 | public function getDeliveryCountry(): string |
||
| 283 | |||
| 284 | public function getDeliveryCountryCode(): string |
||
| 288 | |||
| 289 | public function getDeliveryFax(): string |
||
| 293 | |||
| 294 | public function getDeliveryName(): string |
||
| 298 | |||
| 299 | public function getDeliveryPhone1(): string |
||
| 303 | |||
| 304 | public function getDeliveryPhone2(): string |
||
| 308 | |||
| 309 | public function getDeliveryZipCode(): string |
||
| 313 | |||
| 314 | public function getEmail(): string |
||
| 318 | |||
| 319 | public function getEmailInvoice(): string |
||
| 323 | |||
| 324 | public function getEmailInvoiceBCC(): string |
||
| 328 | |||
| 329 | public function getEmailInvoiceCC(): string |
||
| 333 | |||
| 334 | public function getEmailOffer(): string |
||
| 338 | |||
| 339 | public function getEmailOfferBCC(): string |
||
| 343 | |||
| 344 | public function getEmailOfferCC(): string |
||
| 348 | |||
| 349 | public function getEmailOrder(): string |
||
| 353 | |||
| 354 | public function getEmailOrderBCC(): string |
||
| 358 | |||
| 359 | public function getEmailOrderCC(): string |
||
| 363 | |||
| 364 | public function getFax(): string |
||
| 368 | |||
| 369 | public function getInvoiceAdministrationFee(): string |
||
| 373 | |||
| 374 | public function getInvoiceDiscount(): string |
||
| 378 | |||
| 379 | public function getInvoiceFreight(): string |
||
| 383 | |||
| 384 | public function getInvoiceRemark(): string |
||
| 388 | |||
| 389 | public function getName(): string |
||
| 393 | |||
| 394 | public function getOrganisationNumber(): string |
||
| 398 | |||
| 399 | public function getOurReference(): string |
||
| 403 | |||
| 404 | public function getPhone1(): string |
||
| 408 | |||
| 409 | public function getPhone2(): string |
||
| 413 | |||
| 414 | public function getPriceList(): string |
||
| 418 | |||
| 419 | public function getProject(): string |
||
| 423 | |||
| 424 | public function getSalesAccount(): string |
||
| 428 | |||
| 429 | public function getShowPriceVATIncluded(): string |
||
| 433 | |||
| 434 | public function getTermsOfDelivery(): string |
||
| 438 | |||
| 439 | public function getTermsOfPayment(): string |
||
| 443 | |||
| 444 | public function getType(): string |
||
| 448 | |||
| 449 | public function getVatNumber(): string |
||
| 453 | |||
| 454 | public function getVatType(): string |
||
| 458 | |||
| 459 | public function getVisitingAddress(): string |
||
| 463 | |||
| 464 | public function getVisitingCity(): string |
||
| 468 | |||
| 469 | public function getVisitingCountry(): string |
||
| 473 | |||
| 474 | public function getVisitingCountryCode(): string |
||
| 478 | |||
| 479 | public function getVisitingZipCode(): string |
||
| 483 | |||
| 484 | public function getWww(): string |
||
| 488 | |||
| 489 | public function getWayOfDelivery(): string |
||
| 493 | |||
| 494 | public function getYourReference(): string |
||
| 498 | |||
| 499 | public function getZipCode(): string |
||
| 503 | } |
||
| 504 |