Complex classes like CreateOrderRequest 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 CreateOrderRequest, and based on these observations, apply Extract Interface, too.
| 1 | <?php namespace Ntholenaar\MultiSafepayClient\Request; |
||
| 3 | class CreateOrderRequest extends AbstractRequest implements RequestInterface |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * {@inheritdoc} |
||
| 7 | */ |
||
| 8 | protected $httpMethod = 'POST'; |
||
| 9 | |||
| 10 | /** |
||
| 11 | * {@inheritdoc} |
||
| 12 | */ |
||
| 13 | protected $path = 'orders'; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * {@inheritdoc} |
||
| 17 | */ |
||
| 18 | public function validate() |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Get the type. |
||
| 38 | * |
||
| 39 | * @return string|null |
||
| 40 | */ |
||
| 41 | public function getType() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Set the type. |
||
| 48 | * |
||
| 49 | * @param $type |
||
| 50 | * @return $this |
||
| 51 | * @throws \InvalidArgumentException |
||
| 52 | */ |
||
| 53 | public function setType($type) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Get the order identifier. |
||
| 66 | * |
||
| 67 | * @return mixed|null |
||
| 68 | */ |
||
| 69 | public function getOrderId() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Set the order identifier. |
||
| 76 | * |
||
| 77 | * @param $orderId |
||
| 78 | * @return $this |
||
| 79 | */ |
||
| 80 | public function setOrderId($orderId) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Get the currency. |
||
| 89 | * |
||
| 90 | * @return null |
||
| 91 | */ |
||
| 92 | public function getCurrency() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Set the currency. |
||
| 99 | * |
||
| 100 | * @param $currency |
||
| 101 | * @return $this |
||
| 102 | */ |
||
| 103 | public function setCurrency($currency) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Get the amount. |
||
| 112 | * |
||
| 113 | * @return double|null |
||
| 114 | */ |
||
| 115 | public function getAmount() |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Set the amount. |
||
| 122 | * |
||
| 123 | * @param $amount |
||
| 124 | * @return $this |
||
| 125 | */ |
||
| 126 | public function setAmount($amount) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Get the description. |
||
| 135 | * |
||
| 136 | * @return string|null |
||
| 137 | */ |
||
| 138 | public function getDescription() |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Set the description. |
||
| 145 | * |
||
| 146 | * @param $description |
||
| 147 | * @return $this |
||
| 148 | */ |
||
| 149 | public function setDescription($description) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Get the gateway identifier. |
||
| 158 | * |
||
| 159 | * @return string|null |
||
| 160 | */ |
||
| 161 | public function getGatewayId() |
||
| 165 | |||
| 166 | /** |
||
| 167 | * Set the gateway identifier. |
||
| 168 | * |
||
| 169 | * @param $gatewayId |
||
| 170 | * @return $this |
||
| 171 | */ |
||
| 172 | public function setGatewayId($gatewayId) |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Get the value of var1. |
||
| 181 | * |
||
| 182 | * @return string|null |
||
| 183 | */ |
||
| 184 | public function getVar1() |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Set the value of var1. |
||
| 191 | * |
||
| 192 | * @param $var1 |
||
| 193 | * @return $this |
||
| 194 | */ |
||
| 195 | public function setVar1($var1) |
||
| 201 | |||
| 202 | /** |
||
| 203 | * Get the value of var2. |
||
| 204 | * |
||
| 205 | * @return string|null |
||
| 206 | */ |
||
| 207 | public function getVar2() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Set the value of var2. |
||
| 214 | * |
||
| 215 | * @param $var2 |
||
| 216 | * @return $this |
||
| 217 | */ |
||
| 218 | public function setVar2($var2) |
||
| 224 | |||
| 225 | /** |
||
| 226 | * Get the value of var3. |
||
| 227 | * |
||
| 228 | * @return string|null |
||
| 229 | */ |
||
| 230 | public function getVar3() |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Set the value of var3. |
||
| 237 | * |
||
| 238 | * @param $var3 |
||
| 239 | * @return $this |
||
| 240 | */ |
||
| 241 | public function setVar3($var3) |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Get the items. |
||
| 250 | * |
||
| 251 | * @return array|null |
||
| 252 | */ |
||
| 253 | public function getItems() |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Set the items. |
||
| 260 | * |
||
| 261 | * @param array $items |
||
| 262 | * @return $this |
||
| 263 | */ |
||
| 264 | public function setItems(array $items) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * |
||
| 273 | * @return boolean|null |
||
| 274 | */ |
||
| 275 | public function isManual() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * @param $manual |
||
| 282 | * @return $this |
||
| 283 | */ |
||
| 284 | public function setManual($manual) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @return int|null |
||
| 293 | */ |
||
| 294 | public function getDaysActive() |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @param $days |
||
| 301 | * @return $this |
||
| 302 | */ |
||
| 303 | public function setDaysActive($days) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * Get the payment options. |
||
| 312 | * |
||
| 313 | * @return mixed|null |
||
| 314 | */ |
||
| 315 | public function getPaymentOptions() |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Set the payment options. |
||
| 322 | * |
||
| 323 | * @param array $paymentOptions |
||
| 324 | * @return $this |
||
| 325 | */ |
||
| 326 | public function setPaymentOptions(array $paymentOptions) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Get the customer details. |
||
| 338 | * |
||
| 339 | * @return mixed|null |
||
| 340 | */ |
||
| 341 | public function getCustomer() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Set the customer details. |
||
| 348 | * |
||
| 349 | * @param array $customer |
||
| 350 | * @return $this |
||
| 351 | */ |
||
| 352 | public function setCustomer(array $customer) |
||
| 358 | } |
||
| 359 |