Complex classes like PurchaseRequest 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 PurchaseRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class PurchaseRequest extends AbstractRequest |
||
| 11 | { |
||
| 12 | /** @var string */ |
||
| 13 | protected $liveEndpoint = 'https://sis.redsys.es/sis/realizarPago'; |
||
| 14 | /** @var string */ |
||
| 15 | protected $testEndpoint = 'https://sis-t.redsys.es:25443/sis/realizarPago'; |
||
| 16 | /** @var array */ |
||
| 17 | protected static $consumerLanguages = array( |
||
| 18 | 'es' => '001', // Spanish |
||
| 19 | 'en' => '002', // English |
||
| 20 | 'ca' => '003', // Catalan - same as Valencian (010) |
||
| 21 | 'fr' => '004', // French |
||
| 22 | 'de' => '005', // German |
||
| 23 | 'nl' => '006', // Dutch |
||
| 24 | 'it' => '007', // Italian |
||
| 25 | 'sv' => '008', // Swedish |
||
| 26 | 'pt' => '009', // Portuguese |
||
| 27 | 'pl' => '011', // Polish |
||
| 28 | 'gl' => '012', // Galician |
||
| 29 | 'eu' => '013', // Basque |
||
| 30 | ); |
||
| 31 | |||
| 32 | 2 | public function getCardholder() |
|
| 36 | |||
| 37 | 4 | public function setCardholder($value) |
|
| 41 | |||
| 42 | 8 | public function getConsumerLanguage() |
|
| 46 | |||
| 47 | /** |
||
| 48 | * Set the language presented to the consumer |
||
| 49 | * |
||
| 50 | * @param string|int Either the ISO 639-1 code to be converted, or the gateway's own numeric language code |
||
| 51 | */ |
||
| 52 | 7 | public function setConsumerLanguage($value) |
|
| 65 | |||
| 66 | 15 | public function getHmacKey() |
|
| 70 | |||
| 71 | 23 | public function setHmacKey($value) |
|
| 75 | |||
| 76 | 7 | public function getMerchantData() |
|
| 80 | |||
| 81 | 7 | public function setMerchantData($value) |
|
| 85 | |||
| 86 | 11 | public function getMerchantId() |
|
| 90 | |||
| 91 | 23 | public function setMerchantId($value) |
|
| 95 | |||
| 96 | 11 | public function getMerchantName() |
|
| 100 | |||
| 101 | 23 | public function setMerchantName($value) |
|
| 105 | |||
| 106 | 11 | public function getTerminalId() |
|
| 110 | |||
| 111 | 23 | public function setTerminalId($value) |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Get the shippingCountry field |
||
| 118 | * |
||
| 119 | * @return int The shipping country as an ISO3166 numeric code, e.g. 840 for USA. |
||
| 120 | */ |
||
| 121 | 15 | public function getShippingCountry() |
|
| 125 | 15 | ||
| 126 | 15 | /** |
|
| 127 | 15 | * Set the shippingCountry field |
|
| 128 | 15 | * |
|
| 129 | 15 | * @param int $value The shipping country as an ISO3166 numeric code, e.g. 840 for USA. |
|
| 130 | * @return self |
||
| 131 | 15 | */ |
|
| 132 | 15 | public function setShippingCountry($value) |
|
| 136 | |||
| 137 | 2 | /** |
|
| 138 | * Get the shippingCity field |
||
| 139 | 2 | * |
|
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function getShippingCity() |
||
| 146 | 2 | ||
| 147 | 2 | /** |
|
| 148 | 2 | * Set the shippingCity field |
|
| 149 | 2 | * |
|
| 150 | * @param string $value |
||
| 151 | 2 | * @return self |
|
| 152 | 2 | */ |
|
| 153 | 2 | public function setShippingCity($value) |
|
| 157 | 2 | ||
| 158 | 2 | /** |
|
| 159 | * Get the shippingState field |
||
| 160 | * |
||
| 161 | 1 | * @return string |
|
| 162 | */ |
||
| 163 | 1 | public function getShippingState() |
|
| 167 | |||
| 168 | 1 | /** |
|
| 169 | 1 | * Set the shippingState field |
|
| 170 | 1 | * |
|
| 171 | 1 | * @param string $value |
|
| 172 | 1 | * @return self |
|
| 173 | 1 | */ |
|
| 174 | 1 | public function setShippingState($value) |
|
| 178 | |||
| 179 | /** |
||
| 180 | 7 | * Get the shippingAddress3 field |
|
| 181 | * |
||
| 182 | 7 | * @return string |
|
| 183 | */ |
||
| 184 | public function getShippingAddress3() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Set the shippingAddress3 field |
||
| 191 | * |
||
| 192 | * @param string $value |
||
| 193 | * @return self |
||
| 194 | */ |
||
| 195 | public function setShippingAddress3($value) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * Get the shippingAddress2 field |
||
| 202 | * |
||
| 203 | * @return string |
||
| 204 | */ |
||
| 205 | public function getShippingAddress2() |
||
| 209 | |||
| 210 | /** |
||
| 211 | * Set the shippingAddress2 field |
||
| 212 | * |
||
| 213 | * @param string $value |
||
| 214 | * @return self |
||
| 215 | */ |
||
| 216 | public function setShippingAddress2($value) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Get the shippingAddress1 field |
||
| 223 | * |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | public function getShippingAddress1() |
||
| 230 | |||
| 231 | /** |
||
| 232 | * Set the shippingAddress1 field |
||
| 233 | * |
||
| 234 | * @param string $value |
||
| 235 | * @return self |
||
| 236 | */ |
||
| 237 | public function setShippingAddress1($value) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * Get the shippingPostcode field |
||
| 244 | * |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | public function getShippingPostcode() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Set the shippingPostcode field |
||
| 254 | * |
||
| 255 | * @param string $value |
||
| 256 | * @return self |
||
| 257 | */ |
||
| 258 | public function setShippingPostcode($value) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * Get the email field |
||
| 265 | * |
||
| 266 | * @return string |
||
| 267 | */ |
||
| 268 | public function getEmail() |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Set the email field |
||
| 275 | * |
||
| 276 | * @param string $value |
||
| 277 | * @return self |
||
| 278 | */ |
||
| 279 | public function setEmail($value) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Override the abstract method to add requirement that it must start with 4 numeric characters |
||
| 286 | * |
||
| 287 | * @param string|int $value The transaction ID (merchant order) to set for the transaction |
||
| 288 | */ |
||
| 289 | public function setTransactionId($value) |
||
| 304 | |||
| 305 | public function getData() |
||
| 344 | |||
| 345 | public function sendData($data) |
||
| 363 | |||
| 364 | public function getEndpoint() |
||
| 368 | } |
||
| 369 |