Complex classes like PersonalContainer 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 PersonalContainer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 12 | class PersonalContainer extends AbstractContainer |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Merchant's customer ID (Permitted symbols: 0-9, a-z, A-Z, .,-,_,/) |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected $customerid; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * PAYONE debtor ID |
||
| 23 | * |
||
| 24 | * @var int |
||
| 25 | */ |
||
| 26 | protected $userid; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $salutation; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | protected $title; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var string |
||
| 40 | */ |
||
| 41 | protected $firstname; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | protected $lastname; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string |
||
| 50 | */ |
||
| 51 | protected $company; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | protected $street; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | protected $addressaddition; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | protected $zip; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @var string |
||
| 70 | */ |
||
| 71 | protected $city; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Country (ISO-3166) |
||
| 75 | * |
||
| 76 | * @var string |
||
| 77 | */ |
||
| 78 | protected $country; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | protected $state; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @var string |
||
| 87 | */ |
||
| 88 | protected $email; |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @var string |
||
| 92 | */ |
||
| 93 | protected $telephonenumber; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Date of birth (YYYYMMDD) |
||
| 97 | * |
||
| 98 | * @var int |
||
| 99 | */ |
||
| 100 | protected $birthday; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Language indicator (ISO639) |
||
| 104 | * |
||
| 105 | * @var string |
||
| 106 | */ |
||
| 107 | protected $language; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var string |
||
| 111 | */ |
||
| 112 | protected $vatid; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var string |
||
| 116 | */ |
||
| 117 | protected $gender; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | protected $personalId; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var string |
||
| 126 | */ |
||
| 127 | protected $ip; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @param string $addressaddition |
||
| 131 | * |
||
| 132 | * @return void |
||
| 133 | */ |
||
| 134 | public function setAddressAddition($addressaddition) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @return string|null |
||
| 141 | */ |
||
| 142 | public function getAddressAddition() |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @param string $birthday |
||
| 149 | * |
||
| 150 | * @return void |
||
| 151 | */ |
||
| 152 | public function setBirthday($birthday) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | public function getBirthday() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param string $city |
||
| 167 | * |
||
| 168 | * @return void |
||
| 169 | */ |
||
| 170 | public function setCity($city) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return string|null |
||
| 177 | */ |
||
| 178 | public function getCity() |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @param string $company |
||
| 185 | * |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | public function setCompany($company) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * @return string|null |
||
| 195 | */ |
||
| 196 | public function getCompany() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param string $country |
||
| 203 | * |
||
| 204 | * @return void |
||
| 205 | */ |
||
| 206 | public function setCountry($country) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @return string |
||
| 213 | */ |
||
| 214 | public function getCountry() |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @param string $customerid |
||
| 221 | * |
||
| 222 | * @return void |
||
| 223 | */ |
||
| 224 | public function setCustomerId($customerid) |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | public function getCustomerId() |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @param string $email |
||
| 239 | * |
||
| 240 | * @return void |
||
| 241 | */ |
||
| 242 | public function setEmail($email) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return string|null |
||
| 249 | */ |
||
| 250 | public function getEmail() |
||
| 254 | |||
| 255 | /** |
||
| 256 | * @param string $firstname |
||
| 257 | * |
||
| 258 | * @return void |
||
| 259 | */ |
||
| 260 | public function setFirstName($firstname) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @return string|null |
||
| 267 | */ |
||
| 268 | public function getFirstName() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * @param string $ip |
||
| 275 | * |
||
| 276 | * @return void |
||
| 277 | */ |
||
| 278 | public function setIp($ip) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @return string|null |
||
| 285 | */ |
||
| 286 | public function getIp() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @param string $language |
||
| 293 | * |
||
| 294 | * @return void |
||
| 295 | */ |
||
| 296 | public function setLanguage($language) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public function getLanguage() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param string $lastname |
||
| 311 | * |
||
| 312 | * @return void |
||
| 313 | */ |
||
| 314 | public function setLastName($lastname) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @return string|null |
||
| 321 | */ |
||
| 322 | public function getLastName() |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @param string $salutation |
||
| 329 | * |
||
| 330 | * @return void |
||
| 331 | */ |
||
| 332 | public function setSalutation($salutation) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @return string|null |
||
| 339 | */ |
||
| 340 | public function getSalutation() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @param string $state |
||
| 347 | * |
||
| 348 | * @return void |
||
| 349 | */ |
||
| 350 | public function setState($state) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * @return string|null |
||
| 357 | */ |
||
| 358 | public function getState() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @param string $street |
||
| 365 | * |
||
| 366 | * @return void |
||
| 367 | */ |
||
| 368 | public function setStreet($street) |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @return string|null |
||
| 375 | */ |
||
| 376 | public function getStreet() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @param string $telephonenumber |
||
| 383 | * |
||
| 384 | * @return void |
||
| 385 | */ |
||
| 386 | public function setTelephoneNumber($telephonenumber) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @return string|null |
||
| 393 | */ |
||
| 394 | public function getTelephoneNumber() |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @param string $title |
||
| 401 | * |
||
| 402 | * @return void |
||
| 403 | */ |
||
| 404 | public function setTitle($title) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return string |
||
| 411 | */ |
||
| 412 | public function getTitle() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @param string $userid |
||
| 419 | * |
||
| 420 | * @return void |
||
| 421 | */ |
||
| 422 | public function setUserId($userid) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @return string |
||
| 429 | */ |
||
| 430 | public function getUserId() |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @param string $vatid |
||
| 437 | * |
||
| 438 | * @return void |
||
| 439 | */ |
||
| 440 | public function setVatId($vatid) |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @return string |
||
| 447 | */ |
||
| 448 | public function getVatId() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @param string $gender |
||
| 455 | * |
||
| 456 | * @return void |
||
| 457 | */ |
||
| 458 | public function setGender($gender) |
||
| 462 | |||
| 463 | /** |
||
| 464 | * @return string |
||
| 465 | */ |
||
| 466 | public function getGender() |
||
| 470 | |||
| 471 | /** |
||
| 472 | * @param string $personalId |
||
| 473 | * |
||
| 474 | * @return void |
||
| 475 | */ |
||
| 476 | public function setPersonalId($personalId) |
||
| 477 | { |
||
| 478 | $this->personalId = $personalId; |
||
| 479 | } |
||
| 480 | |||
| 481 | /** |
||
| 482 | * @return string |
||
| 483 | */ |
||
| 484 | public function getPersonalId() |
||
| 485 | { |
||
| 486 | return $this->personalId; |
||
| 487 | } |
||
| 488 | |||
| 489 | /** |
||
| 490 | * @param string $zip |
||
| 491 | * |
||
| 492 | * @return void |
||
| 493 | */ |
||
| 494 | public function setZip($zip) |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @return string |
||
| 501 | */ |
||
| 502 | public function getZip() |
||
| 506 | } |
||
| 507 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.