Complex classes like PersonalData 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 PersonalData, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 33 | class Payone_Api_Request_Parameter_Authorization_PersonalData |
||
| 34 | extends Payone_Api_Request_Parameter_Authorization_Abstract |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * Merchant's customer ID (Permitted symbols: 0-9, a-z, A-Z, .,-,_,/) |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $customerid = null; |
||
| 41 | /** |
||
| 42 | * PAYONE debtor ID |
||
| 43 | * |
||
| 44 | * @var int |
||
| 45 | */ |
||
| 46 | protected $userid = NULL; |
||
| 47 | protected $salutation = null; |
||
| 48 | protected $title = null; |
||
| 49 | protected $firstname = null; |
||
| 50 | protected $lastname = null; |
||
| 51 | protected $company = null; |
||
| 52 | protected $street = null; |
||
| 53 | protected $addressaddition = null; |
||
| 54 | protected $zip = null; |
||
| 55 | protected $city = null; |
||
| 56 | /** |
||
| 57 | * Country (ISO-3166) |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | protected $country = null; |
||
| 62 | protected $state = null; |
||
| 63 | protected $email = null; |
||
| 64 | protected $telephonenumber = null; |
||
| 65 | /** |
||
| 66 | * Date of birth (YYYYMMDD) |
||
| 67 | * |
||
| 68 | * @var int |
||
| 69 | */ |
||
| 70 | protected $birthday = NULL; |
||
| 71 | /** |
||
| 72 | * Language indicator (ISO639) |
||
| 73 | * |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | protected $language = null; |
||
| 77 | protected $vatid = null; |
||
| 78 | protected $ip = null; |
||
| 79 | /** |
||
| 80 | * Enum Gender |
||
| 81 | * @var string |
||
| 82 | */ |
||
| 83 | protected $gender = null; |
||
| 84 | /** |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | protected $personalid = null; |
||
| 88 | |||
| 89 | public function setAddressaddition($addressaddition) |
||
| 93 | |||
| 94 | public function getAddressaddition() |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @param string $birthday |
||
| 101 | */ |
||
| 102 | public function setBirthday($birthday) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | public function getBirthday() |
||
| 114 | |||
| 115 | public function setCity($city) |
||
| 119 | |||
| 120 | public function getCity() |
||
| 124 | |||
| 125 | public function setCompany($company) |
||
| 129 | |||
| 130 | public function getCompany() |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param string $country |
||
| 137 | */ |
||
| 138 | public function setCountry($country) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @return string |
||
| 145 | */ |
||
| 146 | public function getCountry() |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @param string $customerid |
||
| 153 | */ |
||
| 154 | public function setCustomerid($customerid) |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | public function getCustomerid() |
||
| 166 | |||
| 167 | public function setEmail($email) |
||
| 171 | |||
| 172 | public function getEmail() |
||
| 176 | |||
| 177 | public function setFirstname($firstname) |
||
| 181 | |||
| 182 | public function getFirstname() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $gender |
||
| 189 | */ |
||
| 190 | public function setGender($gender) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | public function getGender() |
||
| 202 | |||
| 203 | public function setIp($ip) |
||
| 207 | |||
| 208 | public function getIp() |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @param string $language |
||
| 215 | */ |
||
| 216 | public function setLanguage($language) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | public function getLanguage() |
||
| 228 | |||
| 229 | public function setLastname($lastname) |
||
| 233 | |||
| 234 | public function getLastname() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @param string $personalid |
||
| 241 | */ |
||
| 242 | public function setPersonalid($personalid) |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @return string |
||
| 249 | */ |
||
| 250 | public function getPersonalid() |
||
| 254 | |||
| 255 | public function setSalutation($salutation) |
||
| 259 | |||
| 260 | public function getSalutation() |
||
| 264 | |||
| 265 | public function setState($state) |
||
| 269 | |||
| 270 | public function getState() |
||
| 274 | |||
| 275 | public function setStreet($street) |
||
| 279 | |||
| 280 | public function getStreet() |
||
| 284 | |||
| 285 | public function setTelephonenumber($telephonenumber) |
||
| 289 | |||
| 290 | public function getTelephonenumber() |
||
| 294 | |||
| 295 | public function setTitle($title) |
||
| 299 | |||
| 300 | public function getTitle() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @param string $userid |
||
| 307 | */ |
||
| 308 | public function setUserid($userid) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @return string |
||
| 315 | */ |
||
| 316 | public function getUserid() |
||
| 320 | |||
| 321 | public function setVatid($vatid) |
||
| 325 | |||
| 326 | public function getVatid() |
||
| 330 | |||
| 331 | public function setZip($zip) |
||
| 335 | |||
| 336 | public function getZip() |
||
| 340 | } |
||
| 341 |
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.