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 | * Sub account ID |
||
| 26 | * |
||
| 27 | * @var int |
||
| 28 | */ |
||
| 29 | protected $aid = NULL; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | protected $clearingtype = NULL; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Total amount (in smallest currency unit! e.g. cent) |
||
| 38 | * |
||
| 39 | * @var int |
||
| 40 | */ |
||
| 41 | protected $amount = NULL; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Currency (ISO-4217) |
||
| 45 | * |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | protected $currency = NULL; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * dynamic text for debit and creditcard payments |
||
| 52 | * |
||
| 53 | * @var string |
||
| 54 | */ |
||
| 55 | protected $narrative_text = NULL; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @var Payone_Api_Request_Parameter_Authorization_DeliveryData |
||
| 59 | */ |
||
| 60 | protected $deliveryData = null; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @var string |
||
| 64 | */ |
||
| 65 | protected $financingtype = NULL; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * With the first genericpayment the workorderid will be generated from the |
||
| 69 | * PAYONE platform and will be sent to you in the response. The ID is unique. |
||
| 70 | * The returned workorderid is mandatory for the following requests of |
||
| 71 | * PayPal Express Checkout. |
||
| 72 | * |
||
| 73 | * @var string |
||
| 74 | */ |
||
| 75 | protected $workorderid = NULL; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Wallet provider PPE: PayPal Express |
||
| 79 | * @var Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet |
||
| 80 | */ |
||
| 81 | protected $wallet = null; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @var Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay |
||
| 85 | */ |
||
| 86 | protected $ratePay = null; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Mandatory for PayPal ECS: |
||
| 90 | * 1. action=setexpresscheckout |
||
| 91 | * 2. action=getexpresscheckoutdetails |
||
| 92 | * |
||
| 93 | * @var Payone_Api_Request_Parameter_Paydata_Paydata |
||
| 94 | */ |
||
| 95 | protected $paydata = NULL; |
||
| 96 | |||
| 97 | protected $company = null; |
||
| 98 | protected $firstname = null; |
||
| 99 | protected $lastname = null; |
||
| 100 | protected $street = null; |
||
| 101 | protected $zip = null; |
||
| 102 | protected $city = null; |
||
| 103 | protected $country = null; |
||
| 104 | |||
| 105 | protected $api_version = null; |
||
| 106 | protected $birthday = null; |
||
| 107 | protected $email = null; |
||
| 108 | protected $ip = null; |
||
| 109 | protected $language = null; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @param array $data |
||
| 113 | */ |
||
| 114 | public function __construct(array $data = array()) |
||
| 119 | |||
| 120 | |||
| 121 | /** |
||
| 122 | * @param int $aid |
||
| 123 | */ |
||
| 124 | public function setAid($aid) { |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @return int |
||
| 130 | */ |
||
| 131 | public function getAid() { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param int $amount |
||
| 137 | */ |
||
| 138 | public function setAmount($amount) { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return int |
||
| 144 | */ |
||
| 145 | public function getAmount() { |
||
| 148 | |||
| 149 | /** |
||
| 150 | * @param string $clearingtype |
||
| 151 | */ |
||
| 152 | public function setClearingtype($clearingtype) { |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @return string |
||
| 158 | */ |
||
| 159 | public function getClearingtype() { |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @param string $financingtype |
||
| 165 | */ |
||
| 166 | public function setFinancingType($financingtype) { |
||
| 169 | |||
| 170 | /** |
||
| 171 | * @return string |
||
| 172 | */ |
||
| 173 | public function getFinancingType() { |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param string $currency |
||
| 179 | */ |
||
| 180 | public function setCurrency($currency) { |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @return string |
||
| 186 | */ |
||
| 187 | public function getCurrency() { |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $narrative_text |
||
| 193 | */ |
||
| 194 | public function setNarrativeText($narrative_text) { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | public function getNarrativeText() { |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param Payone_Api_Request_Parameter_Authorization_DeliveryData $deliveryData |
||
| 207 | */ |
||
| 208 | public function setDeliveryData(Payone_Api_Request_Parameter_Authorization_DeliveryData $deliveryData) { |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return Payone_Api_Request_Parameter_Authorization_DeliveryData |
||
| 214 | */ |
||
| 215 | public function getDeliveryData() { |
||
| 218 | |||
| 219 | /** |
||
| 220 | * |
||
| 221 | * @return string |
||
| 222 | */ |
||
| 223 | function getWorkorderId() { |
||
| 226 | |||
| 227 | /** |
||
| 228 | * |
||
| 229 | * @param string $workorderid |
||
| 230 | */ |
||
| 231 | function setWorkorderId($workorderid) { |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @return Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay |
||
| 237 | */ |
||
| 238 | function getRatePay(){ |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay $ratePay |
||
| 244 | */ |
||
| 245 | function setRatePay(Payone_Api_Request_Parameter_Authorization_PaymentMethod_RatePay $ratePay){ |
||
| 248 | |||
| 249 | /** |
||
| 250 | * |
||
| 251 | * @return Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet |
||
| 252 | */ |
||
| 253 | function getWallet() { |
||
| 256 | |||
| 257 | /** |
||
| 258 | * |
||
| 259 | * @param Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet $wallet |
||
| 260 | */ |
||
| 261 | function setWallet(Payone_Api_Request_Parameter_Authorization_PaymentMethod_Wallet $wallet) { |
||
| 264 | |||
| 265 | /** |
||
| 266 | * @param Payone_Api_Request_Parameter_Paydata_Paydata $paydata |
||
| 267 | */ |
||
| 268 | public function setPaydata($paydata) { |
||
| 271 | |||
| 272 | /** |
||
| 273 | * |
||
| 274 | * @return Payone_Api_Request_Parameter_Paydata_Paydata |
||
| 275 | */ |
||
| 276 | public function getPaydata() { |
||
| 279 | |||
| 280 | public function setCompany($company) { |
||
| 283 | |||
| 284 | public function getCompany() { |
||
| 287 | |||
| 288 | public function setFirstname($firstname) { |
||
| 291 | |||
| 292 | public function getFirstname() { |
||
| 295 | |||
| 296 | public function setLastname($lastname) { |
||
| 299 | |||
| 300 | public function getLastname() { |
||
| 303 | |||
| 304 | public function setStreet($street) { |
||
| 307 | |||
| 308 | public function getStreet() { |
||
| 311 | |||
| 312 | public function setZip($zip) { |
||
| 315 | |||
| 316 | public function getZip() { |
||
| 319 | |||
| 320 | public function setCity($city) { |
||
| 323 | |||
| 324 | public function getCity() { |
||
| 327 | |||
| 328 | public function setCountry($country) { |
||
| 331 | |||
| 332 | public function getCountry() { |
||
| 335 | |||
| 336 | public function setApiVersion($api_version) |
||
| 340 | |||
| 341 | public function getApiVersion() |
||
| 345 | |||
| 346 | public function setBirthday($birthday) |
||
| 350 | |||
| 351 | public function getBirthday() |
||
| 355 | |||
| 356 | public function setEmail($email) |
||
| 360 | |||
| 361 | public function getEmail() |
||
| 365 | |||
| 366 | public function setIp($ip) |
||
| 370 | |||
| 371 | public function getIp() |
||
| 375 | |||
| 376 | public function setLanguage($language) |
||
| 380 | |||
| 381 | public function getLanguage() |
||
| 385 | |||
| 386 | } |
||
| 387 |
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.