Complex classes like Invoice 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 Invoice, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class Invoice implements CreatableFromArray |
||
| 10 | { |
||
| 11 | /** @var string|null */ |
||
| 12 | private $url; |
||
| 13 | /** @var string|null */ |
||
| 14 | private $urlTaxReductionList; |
||
| 15 | /** @var string|null */ |
||
| 16 | private $address1; |
||
| 17 | /** @var string|null */ |
||
| 18 | private $address2; |
||
| 19 | /** @var int|null */ |
||
| 20 | private $administrationFee; |
||
| 21 | /** @var int|null */ |
||
| 22 | private $administrationFeeVat; |
||
| 23 | /** @var int|null */ |
||
| 24 | private $balance; |
||
| 25 | /** @var int|null */ |
||
| 26 | private $basisTaxReduction; |
||
| 27 | /** @var bool */ |
||
| 28 | private $booked; |
||
| 29 | /** @var bool */ |
||
| 30 | private $cancelled; |
||
| 31 | /** @var string|null */ |
||
| 32 | private $city; |
||
| 33 | /** @var string|null */ |
||
| 34 | private $comments; |
||
| 35 | /** @var int|null */ |
||
| 36 | private $contractReference; |
||
| 37 | /** @var float|null */ |
||
| 38 | private $contributionPercent; |
||
| 39 | /** @var int|null */ |
||
| 40 | private $contributionValue; |
||
| 41 | /** @var string|null */ |
||
| 42 | private $costCenter; |
||
| 43 | /** @var string|null */ |
||
| 44 | private $country; |
||
| 45 | /** |
||
| 46 | * @var string|null It looks like this is a boolean in a string.. "false". |
||
| 47 | */ |
||
| 48 | private $credit; |
||
| 49 | /** @var string|null */ |
||
| 50 | private $creditInvoiceReference; |
||
| 51 | /** @var string|null */ |
||
| 52 | private $currency; |
||
| 53 | /** @var int|null */ |
||
| 54 | private $currencyRate; |
||
| 55 | /** @var int|null */ |
||
| 56 | private $currencyUnit; |
||
| 57 | /** @var string|null */ |
||
| 58 | private $customerName; |
||
| 59 | /** @var string|null */ |
||
| 60 | private $customerNumber; |
||
| 61 | /** @var string|null */ |
||
| 62 | private $deliveryAddress1; |
||
| 63 | /** @var string|null */ |
||
| 64 | private $deliveryAddress2; |
||
| 65 | /** @var string|null */ |
||
| 66 | private $deliveryCity; |
||
| 67 | /** @var string|null */ |
||
| 68 | private $deliveryCountry; |
||
| 69 | /** @var string|null */ |
||
| 70 | private $deliveryDate; |
||
| 71 | /** @var string|null */ |
||
| 72 | private $deliveryName; |
||
| 73 | /** @var string|null */ |
||
| 74 | private $deliveryZipCode; |
||
| 75 | /** @var string|null */ |
||
| 76 | private $documentNumber; |
||
| 77 | /** @var string|null */ |
||
| 78 | private $dueDate; |
||
| 79 | /** @var array */ |
||
| 80 | private $ediInformation; |
||
| 81 | /** @var string|null */ |
||
| 82 | private $euQuarterlyReport; |
||
| 83 | /** @var array */ |
||
| 84 | private $emailInformation; |
||
| 85 | /** @var string|null */ |
||
| 86 | private $externalInvoiceReference1; |
||
| 87 | /** @var string|null */ |
||
| 88 | private $externalInvoiceReference2; |
||
| 89 | /** @var int|null */ |
||
| 90 | private $freight; |
||
| 91 | /** @var float|null */ |
||
| 92 | private $freightVat; |
||
| 93 | /** @var int|null */ |
||
| 94 | private $gross; |
||
| 95 | /** @var bool */ |
||
| 96 | private $houseWork; |
||
| 97 | /** @var string|null */ |
||
| 98 | private $invoiceDate; |
||
| 99 | /** @var string|null */ |
||
| 100 | private $invoicePeriodEnd; |
||
| 101 | /** @var string|null */ |
||
| 102 | private $invoicePeriodStart; |
||
| 103 | /** @var string|null */ |
||
| 104 | private $invoiceReference; |
||
| 105 | /** @var array */ |
||
| 106 | private $InvoiceRows; |
||
| 107 | /** @var string|null */ |
||
| 108 | private $invoiceType; |
||
| 109 | /** @var array */ |
||
| 110 | private $labels; |
||
| 111 | /** @var string|null */ |
||
| 112 | private $language; |
||
| 113 | /** @var string|null */ |
||
| 114 | private $lastRemindDate; |
||
| 115 | /** @var string|null */ |
||
| 116 | private $net; |
||
| 117 | /** @var bool|null */ |
||
| 118 | private $notCompleted; |
||
| 119 | /** @var string|null */ |
||
| 120 | private $ocr; |
||
| 121 | /** @var string|null */ |
||
| 122 | private $offerReference; |
||
| 123 | /** @var string|null */ |
||
| 124 | private $orderReference; |
||
| 125 | /** @var string|null */ |
||
| 126 | private $organisationNumber; |
||
| 127 | /** @var string|null */ |
||
| 128 | private $ourReference; |
||
| 129 | /** @var string|null */ |
||
| 130 | private $paymentWay; |
||
| 131 | /** @var string|null */ |
||
| 132 | private $phone1; |
||
| 133 | /** @var string|null */ |
||
| 134 | private $phone2; |
||
| 135 | /** @var string|null */ |
||
| 136 | private $priceList; |
||
| 137 | /** @var string|null */ |
||
| 138 | private $printTemplate; |
||
| 139 | /** @var string|null */ |
||
| 140 | private $project; |
||
| 141 | /** @var string|null */ |
||
| 142 | private $remarks; |
||
| 143 | /** @var string|null */ |
||
| 144 | private $reminders; |
||
| 145 | /** @var string|null */ |
||
| 146 | private $roundOff; |
||
| 147 | /** @var bool */ |
||
| 148 | private $sent; |
||
| 149 | /** @var string|null */ |
||
| 150 | private $taxReduction; |
||
| 151 | /** @var string|null */ |
||
| 152 | private $termsOfDelivery; |
||
| 153 | /** @var string|null */ |
||
| 154 | private $termsOfPayment; |
||
| 155 | /** @var int|null */ |
||
| 156 | private $total; |
||
| 157 | /** @var int|null */ |
||
| 158 | private $totalToPay; |
||
| 159 | /** @var float|null */ |
||
| 160 | private $totalVat; |
||
| 161 | /** @var bool|null */ |
||
| 162 | private $vatIncluded; |
||
| 163 | /** @var string|null */ |
||
| 164 | private $voucherNumber; |
||
| 165 | /** @var string|null */ |
||
| 166 | private $voucherSeries; |
||
| 167 | /** @var string|null */ |
||
| 168 | private $voucherYear; |
||
| 169 | /** @var string|null */ |
||
| 170 | private $wayOfDelivery; |
||
| 171 | /** @var string|null */ |
||
| 172 | private $yourOrderNumber; |
||
| 173 | /** @var string|null */ |
||
| 174 | private $yourReference; |
||
| 175 | /** @var string|null */ |
||
| 176 | private $zipCode; |
||
| 177 | |||
| 178 | 2 | private function __construct() |
|
| 181 | |||
| 182 | 2 | public static function createFromArray(array $data) |
|
| 183 | { |
||
| 184 | 2 | $model = new self(); |
|
| 185 | 2 | $data = $data['Invoice'] ?? $data; |
|
| 186 | |||
| 187 | 2 | $model->url = $data['@url'] ?? null; |
|
| 188 | 2 | $model->urlTaxReductionList = $data['@urlTaxReductionList'] ?? null; |
|
| 189 | 2 | $model->address1 = $data['Address1'] ?? ''; |
|
| 190 | 2 | $model->address2 = $data['Address2'] ?? ''; |
|
| 191 | 2 | $model->administrationFee = $data['AdministrationFee'] ?? null; |
|
| 192 | 2 | $model->administrationFeeVat = $data['AdministrationFeeVAT'] ?? null; |
|
| 193 | 2 | $model->balance = $data['Balance'] ?? null; |
|
| 194 | 2 | $model->basisTaxReduction = $data['BasisTaxReduction'] ?? null; |
|
| 195 | 2 | $model->booked = $data['Booked'] ?? false; |
|
| 196 | 2 | $model->cancelled = $data['Cancelled'] ?? false; |
|
| 197 | 2 | $model->city = $data['City'] ?? ''; |
|
| 198 | 2 | $model->comments = $data['Comments'] ?? ''; |
|
| 199 | 2 | $model->contractReference = $data['ContractReference'] ?? null; |
|
| 200 | 2 | $model->contributionPercent = $data['ContributionPercent'] ?? null; |
|
| 201 | 2 | $model->contributionValue = $data['ContributionValue'] ?? null; |
|
| 202 | 2 | $model->costCenter = $data['CostCenter'] ?? ''; |
|
| 203 | 2 | $model->country = $data['Country'] ?? ''; |
|
| 204 | 2 | $model->credit = $data['Credit'] ?? null; |
|
| 205 | 2 | $model->creditInvoiceReference = $data['CreditInvoiceReference'] ?? null; |
|
| 206 | 2 | $model->currency = $data['Currency'] ?? null; |
|
| 207 | 2 | $model->currencyRate = $data['CurrencyRate'] ?? 1; |
|
| 208 | 2 | $model->currencyUnit = $data['CurrencyUnit'] ?? 1; |
|
| 209 | 2 | $model->customerName = $data['CustomerName'] ?? null; |
|
| 210 | 2 | $model->customerNumber = $data['CustomerNumber'] ?? null; |
|
| 211 | 2 | $model->deliveryAddress1 = $data['DeliveryAddress1'] ?? null; |
|
| 212 | 2 | $model->deliveryAddress2 = $data['DeliveryAddress2'] ?? null; |
|
| 213 | 2 | $model->deliveryCity = $data['deliveryCity'] ?? ''; |
|
| 214 | 2 | $model->deliveryCountry = $data['deliveryCountry'] ?? ''; |
|
| 215 | 2 | $model->deliveryDate = $data['DeliveryDate'] ?? null; |
|
| 216 | 2 | $model->deliveryName = $data['DeliveryName'] ?? ''; |
|
| 217 | 2 | $model->deliveryZipCode = $data['DeliveryZipCode'] ?? ''; |
|
| 218 | 2 | $model->documentNumber = $data['DocumentNumber'] ?? null; |
|
| 219 | 2 | $model->dueDate = $data['DueDate'] ?? null; |
|
| 220 | 2 | $model->ediInformation = $data['EDIInformation'] ?? []; |
|
| 221 | 2 | $model->euQuarterlyReport = $data['EUQuarterlyReport'] ?? false; |
|
| 222 | 2 | $model->emailInformation = $data['EmailInformation'] ?? []; |
|
| 223 | 2 | $model->externalInvoiceReference1 = $data['externalInvoiceReference1'] ?? null; |
|
| 224 | 2 | $model->externalInvoiceReference2 = $data['externalInvoiceReference2'] ?? null; |
|
| 225 | 2 | $model->freight = $data['Freight'] ?? null; |
|
| 226 | 2 | $model->freightVat = $data['FreightVAT'] ?? null; |
|
| 227 | 2 | $model->gross = $data['Gross'] ?? null; |
|
| 228 | 2 | $model->houseWork = $data['HouseWork'] ?? false; |
|
| 229 | 2 | $model->invoiceDate = $data['InvoiceDate'] ?? null; |
|
| 230 | 2 | $model->invoicePeriodEnd = $data['InvoicePeriodEnd'] ?? null; |
|
| 231 | 2 | $model->invoicePeriodStart = $data['InvoicePeriodStart'] ?? null; |
|
| 232 | 2 | $model->invoiceReference = $data['InvoiceReference'] ?? null; |
|
| 233 | 2 | $model->InvoiceRows = $data['InvoiceRows'] ?? []; |
|
| 234 | 2 | $model->invoiceType = $data['InvoiceType'] ?? null; |
|
| 235 | 2 | $model->labels = $data['Labels'] ?? []; |
|
| 236 | 2 | $model->language = $data['Language'] ?? null; |
|
| 237 | 2 | $model->lastRemindDate = $data['LastRemindDate'] ?? null; |
|
| 238 | 2 | $model->net = $data['Net'] ?? null; |
|
| 239 | 2 | $model->notCompleted = $data['NotCompleted'] ?? null; |
|
| 240 | 2 | $model->ocr = $data['OCR'] ?? null; |
|
| 241 | 2 | $model->offerReference = $data['OfferReference'] ?? null; |
|
| 242 | 2 | $model->orderReference = $data['OrderReference'] ?? null; |
|
| 243 | 2 | $model->organisationNumber = $data['OrganisationNumber'] ?? null; |
|
| 244 | 2 | $model->ourReference = $data['OurReference'] ?? null; |
|
| 245 | 2 | $model->paymentWay = $data['PaymentWay'] ?? null; |
|
| 246 | 2 | $model->phone1 = $data['Phone1'] ?? null; |
|
| 247 | 2 | $model->phone2 = $data['Phone2'] ?? null; |
|
| 248 | 2 | $model->priceList = $data['PriceList'] ?? null; |
|
| 249 | 2 | $model->printTemplate = $data['PrintTemplate'] ?? null; |
|
| 250 | 2 | $model->project = $data['Project'] ?? null; |
|
| 251 | 2 | $model->remarks = $data['Remarks'] ?? null; |
|
| 252 | 2 | $model->reminders = $data['Reminders'] ?? null; |
|
| 253 | 2 | $model->roundOff = $data['RoundOff'] ?? null; |
|
| 254 | 2 | $model->sent = $data['Sent'] ?? false; |
|
| 255 | 2 | $model->taxReduction = $data['TaxReduction'] ?? null; |
|
| 256 | 2 | $model->termsOfDelivery = $data['TermsOfDelivery'] ?? null; |
|
| 257 | 2 | $model->termsOfPayment = $data['TermsOfPayment'] ?? null; |
|
| 258 | 2 | $model->total = $data['Total'] ?? null; |
|
| 259 | 2 | $model->totalToPay = $data['TotalToPay'] ?? null; |
|
| 260 | 2 | $model->totalVat = $data['TotalVAT'] ?? null; |
|
| 261 | 2 | $model->vatIncluded = $data['VATIncluded'] ?? null; |
|
| 262 | 2 | $model->voucherNumber = $data['VoucherNumber'] ?? null; |
|
| 263 | 2 | $model->voucherSeries = $data['VoucherSeries'] ?? null; |
|
| 264 | 2 | $model->voucherYear = $data['VoucherYear'] ?? null; |
|
| 265 | 2 | $model->wayOfDelivery = $data['WayOfDelivery'] ?? ''; |
|
| 266 | 2 | $model->yourOrderNumber = $data['YourOrderNumber'] ?? ''; |
|
| 267 | 2 | $model->yourReference = $data['YourReference'] ?? ''; |
|
| 268 | 2 | $model->zipCode = $data['ZipCode'] ?? ''; |
|
| 269 | |||
| 270 | 2 | return $model; |
|
| 271 | } |
||
| 272 | |||
| 273 | public function getUrl(): string |
||
| 277 | |||
| 278 | public function getUrlTaxReductionList(): string |
||
| 282 | |||
| 283 | public function getAddress1(): string |
||
| 287 | |||
| 288 | public function getAddress2(): string |
||
| 292 | |||
| 293 | public function getAdministrationFee(): int |
||
| 297 | |||
| 298 | public function getAdministrationFeeVat(): int |
||
| 302 | |||
| 303 | 1 | public function getBalance(): int |
|
| 307 | |||
| 308 | public function getBasisTaxReduction(): int |
||
| 312 | |||
| 313 | public function isBooked(): bool |
||
| 317 | |||
| 318 | public function isCancelled(): bool |
||
| 322 | |||
| 323 | public function getCity(): string |
||
| 327 | |||
| 328 | public function getComments(): string |
||
| 332 | |||
| 333 | public function getContractReference(): int |
||
| 337 | |||
| 338 | public function getContributionPercent(): float |
||
| 342 | |||
| 343 | public function getContributionValue(): int |
||
| 347 | |||
| 348 | public function getCostCenter(): string |
||
| 352 | |||
| 353 | public function getCountry(): string |
||
| 357 | |||
| 358 | public function getCredit(): string |
||
| 362 | |||
| 363 | public function getCreditInvoiceReference(): string |
||
| 367 | |||
| 368 | public function getCurrency(): string |
||
| 372 | |||
| 373 | public function getCurrencyRate(): int |
||
| 377 | |||
| 378 | public function getCurrencyUnit(): int |
||
| 382 | |||
| 383 | public function getCustomerName(): string |
||
| 387 | |||
| 388 | public function getCustomerNumber(): string |
||
| 392 | |||
| 393 | public function getDeliveryAddress1(): string |
||
| 397 | |||
| 398 | public function getDeliveryAddress2(): string |
||
| 402 | |||
| 403 | public function getDeliveryCity(): string |
||
| 407 | |||
| 408 | public function getDeliveryCountry(): string |
||
| 412 | |||
| 413 | public function getDeliveryDate(): \DateTimeInterface |
||
| 417 | |||
| 418 | public function getDeliveryName(): string |
||
| 422 | |||
| 423 | public function getDeliveryZipCode(): string |
||
| 427 | |||
| 428 | public function getDocumentNumber(): string |
||
| 432 | |||
| 433 | public function getDueDate(): \DateTimeInterface |
||
| 437 | |||
| 438 | public function getEdiInformation(): array |
||
| 442 | |||
| 443 | public function getEuQuarterlyReport(): string |
||
| 447 | |||
| 448 | public function getEmailInformation(): array |
||
| 452 | |||
| 453 | public function getExternalInvoiceReference1(): string |
||
| 457 | |||
| 458 | public function getExternalInvoiceReference2(): string |
||
| 462 | |||
| 463 | public function getFreight(): int |
||
| 467 | |||
| 468 | public function getFreightVat(): float |
||
| 472 | |||
| 473 | public function getGross(): int |
||
| 477 | |||
| 478 | public function isHouseWork(): bool |
||
| 482 | |||
| 483 | public function getInvoiceDate(): \DateTimeInterface |
||
| 487 | |||
| 488 | public function getInvoicePeriodEnd(): string |
||
| 492 | |||
| 493 | public function getInvoicePeriodStart(): string |
||
| 497 | |||
| 498 | public function getInvoiceReference(): string |
||
| 502 | |||
| 503 | public function getInvoiceRows(): array |
||
| 507 | |||
| 508 | public function getInvoiceType(): string |
||
| 512 | |||
| 513 | public function getLabels(): array |
||
| 517 | |||
| 518 | public function getLanguage(): string |
||
| 522 | |||
| 523 | public function getLastRemindDate(): \DateTimeInterface |
||
| 527 | |||
| 528 | public function getNet(): string |
||
| 532 | |||
| 533 | public function getNotCompleted(): bool |
||
| 537 | |||
| 538 | public function getOcr(): string |
||
| 542 | |||
| 543 | public function getOfferReference(): string |
||
| 547 | |||
| 548 | public function getOrderReference(): string |
||
| 552 | |||
| 553 | public function getOrganisationNumber(): string |
||
| 557 | |||
| 558 | public function getOurReference(): string |
||
| 562 | |||
| 563 | public function getPaymentWay(): string |
||
| 567 | |||
| 568 | public function getPhone1(): string |
||
| 572 | |||
| 573 | public function getPhone2(): string |
||
| 577 | |||
| 578 | public function getPriceList(): string |
||
| 582 | |||
| 583 | public function getPrintTemplate(): string |
||
| 587 | |||
| 588 | public function getProject(): string |
||
| 592 | |||
| 593 | public function getRemarks(): string |
||
| 597 | |||
| 598 | public function getReminders(): string |
||
| 602 | |||
| 603 | public function getRoundOff(): string |
||
| 607 | |||
| 608 | public function isSent(): bool |
||
| 612 | |||
| 613 | public function getTaxReduction(): string |
||
| 617 | |||
| 618 | public function getTermsOfDelivery(): string |
||
| 622 | |||
| 623 | public function getTermsOfPayment(): string |
||
| 627 | |||
| 628 | public function getTotal(): int |
||
| 632 | |||
| 633 | public function getTotalToPay(): int |
||
| 637 | |||
| 638 | public function getTotalVat(): float |
||
| 642 | |||
| 643 | public function getVatIncluded(): bool |
||
| 647 | |||
| 648 | public function getVoucherNumber(): string |
||
| 652 | |||
| 653 | public function getVoucherSeries(): string |
||
| 657 | |||
| 658 | public function getVoucherYear(): string |
||
| 662 | |||
| 663 | public function getWayOfDelivery(): string |
||
| 667 | |||
| 668 | public function getYourOrderNumber(): string |
||
| 672 | |||
| 673 | public function getYourReference(): string |
||
| 677 | |||
| 678 | public function getZipCode(): string |
||
| 682 | } |
||
| 683 |