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 | * @var Payone_Api_Request_Parameter_Invoicing_Transaction |
||
| 115 | */ |
||
| 116 | protected $invoicing = null; |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @param array $data |
||
| 120 | */ |
||
| 121 | public function __construct(array $data = array()) |
||
| 126 | |||
| 127 | |||
| 128 | /** |
||
| 129 | * @param int $aid |
||
| 130 | */ |
||
| 131 | public function setAid($aid) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return int |
||
| 138 | */ |
||
| 139 | public function getAid() |
||
| 143 | |||
| 144 | /** |
||
| 145 | * @param int $amount |
||
| 146 | */ |
||
| 147 | public function setAmount($amount) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @return int |
||
| 154 | */ |
||
| 155 | public function getAmount() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @param string $clearingtype |
||
| 162 | */ |
||
| 163 | public function setClearingtype($clearingtype) |
||
| 167 | |||
| 168 | /** |
||
| 169 | * @return string |
||
| 170 | */ |
||
| 171 | public function getClearingtype() |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @param string $financingtype |
||
| 178 | */ |
||
| 179 | public function setFinancingType($financingtype) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | public function getFinancingType() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @param string $currency |
||
| 194 | */ |
||
| 195 | public function setCurrency($currency) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @return string |
||
| 202 | */ |
||
| 203 | public function getCurrency() |
||
| 207 | |||
| 208 | /** |
||
| 209 | * @param string $narrative_text |
||
| 210 | */ |
||
| 211 | public function setNarrativeText($narrative_text) |
||
| 215 | |||
| 216 | /** |
||
| 217 | * @return string |
||
| 218 | */ |
||
| 219 | public function getNarrativeText() |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @param Payone_Api_Request_Parameter_Authorization_DeliveryData $deliveryData |
||
| 226 | */ |
||
| 227 | public function setDeliveryData(Payone_Api_Request_Parameter_Authorization_DeliveryData $deliveryData) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * @return Payone_Api_Request_Parameter_Authorization_DeliveryData |
||
| 234 | */ |
||
| 235 | public function getDeliveryData() |
||
| 239 | |||
| 240 | /** |
||
| 241 | * |
||
| 242 | * @return string |
||
| 243 | */ |
||
| 244 | function getWorkorderId() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * |
||
| 251 | * @param string $workorderid |
||
| 252 | */ |
||
| 253 | function setWorkorderId($workorderid) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * @return Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay |
||
| 260 | */ |
||
| 261 | function getRatePay() |
||
| 265 | |||
| 266 | /** |
||
| 267 | * @param Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay $ratePay |
||
| 268 | */ |
||
| 269 | function setRatePay(Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay $ratePay) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * |
||
| 276 | * @return Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet |
||
| 277 | */ |
||
| 278 | function getWallet() |
||
| 282 | |||
| 283 | /** |
||
| 284 | * |
||
| 285 | * @param Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet $wallet |
||
| 286 | */ |
||
| 287 | function setWallet(Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet $wallet) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @param Payone_Api_Request_Parameter_Paydata_Paydata $paydata |
||
| 294 | */ |
||
| 295 | public function setPaydata($paydata) |
||
| 299 | |||
| 300 | /** |
||
| 301 | * |
||
| 302 | * @return Payone_Api_Request_Parameter_Paydata_Paydata |
||
| 303 | */ |
||
| 304 | public function getPaydata() |
||
| 308 | |||
| 309 | public function setCompany($company) |
||
| 313 | |||
| 314 | public function getCompany() |
||
| 318 | |||
| 319 | public function setFirstname($firstname) |
||
| 323 | |||
| 324 | public function getFirstname() |
||
| 328 | |||
| 329 | public function setLastname($lastname) |
||
| 333 | |||
| 334 | public function getLastname() |
||
| 338 | |||
| 339 | public function setStreet($street) |
||
| 343 | |||
| 344 | public function getStreet() |
||
| 348 | |||
| 349 | public function setZip($zip) |
||
| 353 | |||
| 354 | public function getZip() |
||
| 358 | |||
| 359 | public function setCity($city) |
||
| 363 | |||
| 364 | public function getCity() |
||
| 368 | |||
| 369 | public function setCountry($country) |
||
| 373 | |||
| 374 | public function getCountry() |
||
| 378 | |||
| 379 | public function setApiVersion($api_version) |
||
| 383 | |||
| 384 | public function getApiVersion() |
||
| 388 | |||
| 389 | public function setBirthday($birthday) |
||
| 393 | |||
| 394 | public function getBirthday() |
||
| 398 | |||
| 399 | public function setEmail($email) |
||
| 403 | |||
| 404 | public function getEmail() |
||
| 408 | |||
| 409 | public function setIp($ip) |
||
| 413 | |||
| 414 | public function getIp() |
||
| 418 | |||
| 419 | public function setLanguage($language) |
||
| 423 | |||
| 424 | public function getLanguage() |
||
| 428 | |||
| 429 | public function setTelephonenumber($telephonenumber) |
||
| 433 | |||
| 434 | public function getTelephonenumber() |
||
| 438 | |||
| 439 | /** |
||
| 440 | * @param \Payone_Api_Request_Parameter_Invoicing_Transaction $invoicing |
||
| 441 | */ |
||
| 442 | public function setInvoicing(Payone_Api_Request_Parameter_Invoicing_Transaction $invoicing) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @return \Payone_Api_Request_Parameter_Invoicing_Transaction |
||
| 449 | */ |
||
| 450 | public function getInvoicing() |
||
| 454 | |||
| 455 | } |
||
| 456 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.