Complex classes like RegionalInformation 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 RegionalInformation, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class RegionalInformation implements CreatableFromArray |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var int |
||
| 16 | */ |
||
| 17 | private $rotavdrag = 0; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $rotavdragPersonalNumber; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $rotavdragDescription; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var bool |
||
| 31 | */ |
||
| 32 | private $reversedVat = false; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | private $autogiroBetalarnummer; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | private $autogiroPaymentDate; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | private $autogiroStatus; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $autogiroFullStatus; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | private $autogiroTotalSum; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | private $efakturaRecipientIdentifier; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | private $efakturaRecipientType; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | private $efakturaRecipientBankName; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var int |
||
| 76 | */ |
||
| 77 | private $efakturaRecipientBankId; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | private $efakturaRecipientBankCode; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var int |
||
| 86 | */ |
||
| 87 | private $efakturaRecipientIdNumber; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var int |
||
| 91 | */ |
||
| 92 | private $efakturaRequestedAmount; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var CollectionForElectricityInvoices |
||
| 96 | */ |
||
| 97 | private $collectionForElectricityInvoices; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @return int |
||
| 101 | */ |
||
| 102 | public function getRotavdrag(): int |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @param int $rotavdrag |
||
| 109 | * |
||
| 110 | * @return RegionalInformation |
||
| 111 | */ |
||
| 112 | public function withRotavdrag(int $rotavdrag) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | public function getRotavdragPersonalNumber(): string |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param string $rotavdragPersonalNumber |
||
| 130 | * |
||
| 131 | * @return RegionalInformation |
||
| 132 | */ |
||
| 133 | public function withRotavdragPersonalNumber(string $rotavdragPersonalNumber) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @return string |
||
| 143 | */ |
||
| 144 | public function getRotavdragDescription(): string |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param string $rotavdragDescription |
||
| 151 | * |
||
| 152 | * @return RegionalInformation |
||
| 153 | */ |
||
| 154 | public function withRotavdragDescription(string $rotavdragDescription) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @return bool |
||
| 164 | */ |
||
| 165 | public function isReversedVat(): bool |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @param bool $reversedVat |
||
| 172 | * |
||
| 173 | * @return RegionalInformation |
||
| 174 | */ |
||
| 175 | public function withReversedVat(bool $reversedVat) |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | public function getAutogiroBetalarnummer(): string |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $autogiroBetalarnummer |
||
| 193 | * |
||
| 194 | * @return RegionalInformation |
||
| 195 | */ |
||
| 196 | public function withAutogiroBetalarnummer(string $autogiroBetalarnummer) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | public function getAutogiroPaymentDate(): string |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param string $autogiroPaymentDate |
||
| 214 | * |
||
| 215 | * @return RegionalInformation |
||
| 216 | */ |
||
| 217 | public function withAutogiroPaymentDate(string $autogiroPaymentDate) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @return string |
||
| 227 | */ |
||
| 228 | public function getAutogiroStatus(): string |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @param string $autogiroStatus |
||
| 235 | * |
||
| 236 | * @return RegionalInformation |
||
| 237 | */ |
||
| 238 | public function withAutogiroStatus(string $autogiroStatus) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | public function getAutogiroFullStatus(): string |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param string $autogiroFullStatus |
||
| 256 | * |
||
| 257 | * @return RegionalInformation |
||
| 258 | */ |
||
| 259 | public function withAutogiroFullStatus(string $autogiroFullStatus) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @return string |
||
| 269 | */ |
||
| 270 | public function getAutogiroTotalSum(): string |
||
| 274 | |||
| 275 | /** |
||
| 276 | * @param string $autogiroTotalSum |
||
| 277 | * |
||
| 278 | * @return RegionalInformation |
||
| 279 | */ |
||
| 280 | public function withAutogiroTotalSum(string $autogiroTotalSum) |
||
| 287 | |||
| 288 | /** |
||
| 289 | * @return string |
||
| 290 | */ |
||
| 291 | public function getEfakturaRecipientIdentifier(): string |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @param string $efakturaRecipientIdentifier |
||
| 298 | * |
||
| 299 | * @return RegionalInformation |
||
| 300 | */ |
||
| 301 | public function withEfakturaRecipientIdentifier(string $efakturaRecipientIdentifier) |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | public function getEfakturaRecipientType(): string |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @param string $efakturaRecipientType |
||
| 319 | * |
||
| 320 | * @return RegionalInformation |
||
| 321 | */ |
||
| 322 | public function withEfakturaRecipientType(string $efakturaRecipientType) |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return string |
||
| 332 | */ |
||
| 333 | public function getEfakturaRecipientBankName(): string |
||
| 337 | |||
| 338 | /** |
||
| 339 | * @param string $efakturaRecipientBankName |
||
| 340 | * |
||
| 341 | * @return RegionalInformation |
||
| 342 | */ |
||
| 343 | public function withEfakturaRecipientBankName(string $efakturaRecipientBankName) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @return int |
||
| 353 | */ |
||
| 354 | public function getEfakturaRecipientBankId(): int |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @param int $efakturaRecipientBankId |
||
| 361 | * |
||
| 362 | * @return RegionalInformation |
||
| 363 | */ |
||
| 364 | public function withEfakturaRecipientBankId(int $efakturaRecipientBankId) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return string |
||
| 374 | */ |
||
| 375 | public function getEfakturaRecipientBankCode(): string |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @param string $efakturaRecipientBankCode |
||
| 382 | * |
||
| 383 | * @return RegionalInformation |
||
| 384 | */ |
||
| 385 | public function withEfakturaRecipientBankCode(string $efakturaRecipientBankCode) |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @return int |
||
| 395 | */ |
||
| 396 | public function getEfakturaRecipientIdNumber(): int |
||
| 400 | |||
| 401 | /** |
||
| 402 | * @param int $efakturaRecipientIdNumber |
||
| 403 | * |
||
| 404 | * @return RegionalInformation |
||
| 405 | */ |
||
| 406 | public function withEfakturaRecipientIdNumber(int $efakturaRecipientIdNumber) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * @return int |
||
| 416 | */ |
||
| 417 | public function getEfakturaRequestedAmount(): int |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @param int $efakturaRequestedAmount |
||
| 424 | * |
||
| 425 | * @return RegionalInformation |
||
| 426 | */ |
||
| 427 | public function withEfakturaRequestedAmount(int $efakturaRequestedAmount) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @return CollectionForElectricityInvoices |
||
| 437 | */ |
||
| 438 | public function getCollectionForElectricityInvoices(): CollectionForElectricityInvoices |
||
| 442 | |||
| 443 | /** |
||
| 444 | * @param CollectionForElectricityInvoices $collectionForElectricityInvoices |
||
| 445 | * |
||
| 446 | * @return RegionalInformation |
||
| 447 | */ |
||
| 448 | public function withCollectionForElectricityInvoices(CollectionForElectricityInvoices $collectionForElectricityInvoices) |
||
| 455 | |||
| 456 | public function toArray() |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Create an API response object from the HTTP response from the API server. |
||
| 516 | * |
||
| 517 | * @param array $data |
||
| 518 | * |
||
| 519 | * @return self |
||
| 520 | */ |
||
| 521 | 3 | public static function createFromArray(array $data) |
|
| 544 | } |
||
| 545 |