Complex classes like Payone_Api_Request_Genericpayment 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 Payone_Api_Request_Genericpayment, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 22 | class Payone_Api_Request_Genericpayment extends Payone_Api_Request_Abstract |
||
|
|
|||
| 23 | { |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Sub account ID |
||
| 27 | * |
||
| 28 | * @var int |
||
| 29 | */ |
||
| 30 | protected $aid = NULL; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $clearingtype = NULL; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Total amount (in smallest currency unit! e.g. cent) |
||
| 39 | * |
||
| 40 | * @var int |
||
| 41 | */ |
||
| 42 | protected $amount = NULL; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Currency (ISO-4217) |
||
| 46 | * |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | protected $currency = NULL; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * dynamic text for debit and creditcard payments |
||
| 53 | * |
||
| 54 | * @var string |
||
| 55 | */ |
||
| 56 | protected $narrative_text = NULL; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var Payone_Api_Request_Parameter_Authorization_DeliveryData |
||
| 60 | */ |
||
| 61 | protected $deliveryData = null; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var string |
||
| 65 | */ |
||
| 66 | protected $financingtype = NULL; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * With the first genericpayment the workorderid will be generated from the |
||
| 70 | * PAYONE platform and will be sent to you in the response. The ID is unique. |
||
| 71 | * The returned workorderid is mandatory for the following requests of |
||
| 72 | * PayPal Express Checkout. |
||
| 73 | * |
||
| 74 | * @var string |
||
| 75 | */ |
||
| 76 | protected $workorderid = NULL; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Wallet provider PPE: PayPal Express |
||
| 80 | * @var Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet |
||
| 81 | */ |
||
| 82 | protected $wallet = null; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay |
||
| 86 | */ |
||
| 87 | protected $ratePay = null; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Mandatory for PayPal ECS: |
||
| 91 | * 1. action=setexpresscheckout |
||
| 92 | * 2. action=getexpresscheckoutdetails |
||
| 93 | * |
||
| 94 | * @var Payone_Api_Request_Parameter_Paydata_Paydata |
||
| 95 | */ |
||
| 96 | protected $paydata = NULL; |
||
| 97 | |||
| 98 | protected $company = null; |
||
| 99 | protected $firstname = null; |
||
| 100 | protected $lastname = null; |
||
| 101 | protected $street = null; |
||
| 102 | protected $zip = null; |
||
| 103 | protected $city = null; |
||
| 104 | protected $country = null; |
||
| 105 | |||
| 106 | protected $api_version = null; |
||
| 107 | protected $birthday = null; |
||
| 108 | protected $email = null; |
||
| 109 | protected $ip = null; |
||
| 110 | protected $language = null; |
||
| 111 | protected $telephonenumber = null; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @param array $data |
||
| 115 | */ |
||
| 116 | public function __construct(array $data = array()) |
||
| 121 | |||
| 122 | |||
| 123 | /** |
||
| 124 | * @param int $aid |
||
| 125 | */ |
||
| 126 | public function setAid($aid) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @return int |
||
| 133 | */ |
||
| 134 | public function getAid() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @param int $amount |
||
| 141 | */ |
||
| 142 | public function setAmount($amount) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @return int |
||
| 149 | */ |
||
| 150 | public function getAmount() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param string $clearingtype |
||
| 157 | */ |
||
| 158 | public function setClearingtype($clearingtype) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | public function getClearingtype() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param string $financingtype |
||
| 173 | */ |
||
| 174 | public function setFinancingType($financingtype) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public function getFinancingType() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $currency |
||
| 189 | */ |
||
| 190 | public function setCurrency($currency) |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return string |
||
| 197 | */ |
||
| 198 | public function getCurrency() |
||
| 202 | |||
| 203 | /** |
||
| 204 | * @param string $narrative_text |
||
| 205 | */ |
||
| 206 | public function setNarrativeText($narrative_text) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @return string |
||
| 213 | */ |
||
| 214 | public function getNarrativeText() |
||
| 218 | |||
| 219 | /** |
||
| 220 | * @param Payone_Api_Request_Parameter_Authorization_DeliveryData $deliveryData |
||
| 221 | */ |
||
| 222 | public function setDeliveryData(Payone_Api_Request_Parameter_Authorization_DeliveryData $deliveryData) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @return Payone_Api_Request_Parameter_Authorization_DeliveryData |
||
| 229 | */ |
||
| 230 | public function getDeliveryData() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | function getWorkorderId() |
||
| 243 | |||
| 244 | /** |
||
| 245 | * |
||
| 246 | * @param string $workorderid |
||
| 247 | */ |
||
| 248 | function setWorkorderId($workorderid) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @return Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay |
||
| 255 | */ |
||
| 256 | function getRatePay() |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @param Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay $ratePay |
||
| 263 | */ |
||
| 264 | function setRatePay(Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay $ratePay) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * |
||
| 271 | * @return Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet |
||
| 272 | */ |
||
| 273 | function getWallet() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * |
||
| 280 | * @param Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet $wallet |
||
| 281 | */ |
||
| 282 | function setWallet(Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet $wallet) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @param Payone_Api_Request_Parameter_Paydata_Paydata $paydata |
||
| 289 | */ |
||
| 290 | public function setPaydata($paydata) |
||
| 294 | |||
| 295 | /** |
||
| 296 | * |
||
| 297 | * @return Payone_Api_Request_Parameter_Paydata_Paydata |
||
| 298 | */ |
||
| 299 | public function getPaydata() |
||
| 303 | |||
| 304 | public function setCompany($company) |
||
| 308 | |||
| 309 | public function getCompany() |
||
| 313 | |||
| 314 | public function setFirstname($firstname) |
||
| 318 | |||
| 319 | public function getFirstname() |
||
| 323 | |||
| 324 | public function setLastname($lastname) |
||
| 328 | |||
| 329 | public function getLastname() |
||
| 333 | |||
| 334 | public function setStreet($street) |
||
| 338 | |||
| 339 | public function getStreet() |
||
| 343 | |||
| 344 | public function setZip($zip) |
||
| 348 | |||
| 349 | public function getZip() |
||
| 353 | |||
| 354 | public function setCity($city) |
||
| 358 | |||
| 359 | public function getCity() |
||
| 363 | |||
| 364 | public function setCountry($country) |
||
| 368 | |||
| 369 | public function getCountry() |
||
| 373 | |||
| 374 | public function setApiVersion($api_version) |
||
| 378 | |||
| 379 | public function getApiVersion() |
||
| 383 | |||
| 384 | public function setBirthday($birthday) |
||
| 388 | |||
| 389 | public function getBirthday() |
||
| 393 | |||
| 394 | public function setEmail($email) |
||
| 398 | |||
| 399 | public function getEmail() |
||
| 403 | |||
| 404 | public function setIp($ip) |
||
| 408 | |||
| 409 | public function getIp() |
||
| 413 | |||
| 414 | public function setLanguage($language) |
||
| 418 | |||
| 419 | public function getLanguage() |
||
| 423 | |||
| 424 | public function setTelephonenumber($telephonenumber) |
||
| 428 | |||
| 429 | public function getTelephonenumber() |
||
| 433 | |||
| 434 | } |
||
| 435 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.