Complex classes like WebMoneyMerchant 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 WebMoneyMerchant, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 10 | class WebMoneyMerchant |
||
| 11 | { |
||
| 12 | public function __construct() |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Allow the access, if the ip address is in the whitelist. |
||
| 18 | * @param $ip |
||
| 19 | * @return bool |
||
| 20 | */ |
||
| 21 | public function allowIP($ip) |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Generates the '403' error code. |
||
| 33 | * @param $message |
||
| 34 | * @return mixed |
||
| 35 | */ |
||
| 36 | public function responseError($message) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Returns the 'YES' success message. |
||
| 43 | * @return string |
||
| 44 | */ |
||
| 45 | public function responseOK() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Fills in the event details to pass the title and request params as array. |
||
| 52 | * @param $event_type |
||
| 53 | * @param $event_title |
||
| 54 | * @param Request $request |
||
| 55 | */ |
||
| 56 | public function eventFillAndSend($event_type, $event_title, Request $request) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Calculates the signature for the order form. |
||
| 71 | * @param $LMI_PAYMENT_AMOUNT |
||
| 72 | * @param $LMI_PAYMENT_NO |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | public function getFormSignature($LMI_PAYMENT_AMOUNT, $LMI_PAYMENT_NO) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Returns the hash for the params from WebMoneyMerchant. |
||
| 84 | * @param Request $request |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | public function getSignature(Request $request) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Generates the order array with required fields for the order form. |
||
| 106 | * @param $payment_amount |
||
| 107 | * @param $payment_no |
||
| 108 | * @param $item_name |
||
| 109 | * @return array |
||
| 110 | */ |
||
| 111 | public function generateWebMoneyMerchantOrderWithRequiredFields($payment_amount, $payment_no, $item_name) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Checks required order params for the order form and raise an exception if it fails. |
||
| 126 | * @param $order |
||
| 127 | * @throws InvalidConfiguration |
||
| 128 | */ |
||
| 129 | public function requiredOrderParamsCheck($order) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Generates html forms from view with payment buttons |
||
| 156 | * Note: you can customise the view via artisan:publish. |
||
| 157 | * @param $payment_amount |
||
| 158 | * @param $payment_no |
||
| 159 | * @param $item_name |
||
| 160 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 161 | */ |
||
| 162 | public function generatePaymentForm($payment_amount, $payment_no, $item_name) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Validates the request params from WebMoneyMerchant. |
||
| 182 | * @param Request $request |
||
| 183 | * @return bool |
||
| 184 | */ |
||
| 185 | public function validate(Request $request) |
||
| 202 | |||
| 203 | /** |
||
| 204 | * Validates the payee purse from WebMoneyMerchant. |
||
| 205 | * @param Request $request |
||
| 206 | * @return bool |
||
| 207 | */ |
||
| 208 | public function validatePayeePurse(Request $request) |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Validates the request signature from WebMoneyMerchant. |
||
| 219 | * @param Request $request |
||
| 220 | * @return bool |
||
| 221 | */ |
||
| 222 | public function validateSignature(Request $request) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * Validates the allowed ip, request params and signature from WebMoneyMerchant. |
||
| 235 | * @param Request $request |
||
| 236 | * @return bool |
||
| 237 | */ |
||
| 238 | public function validateOrderRequestFromGate(Request $request) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Validates the required attributes of the found order. |
||
| 251 | * @param Request $request |
||
| 252 | * @param $order |
||
| 253 | * @return bool |
||
| 254 | */ |
||
| 255 | public function validateSearchOrderRequiredAttributes(Request $request, $order) |
||
| 283 | |||
| 284 | /** |
||
| 285 | * Calls SearchOrderFilter and check return order params. |
||
| 286 | * @param Request $request |
||
| 287 | * @return bool |
||
| 288 | * @throws InvalidConfiguration |
||
| 289 | */ |
||
| 290 | public function callFilterSearchOrder(Request $request) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * Calls PaidOrderFilter if the order is not paid. |
||
| 318 | * @param Request $request |
||
| 319 | * @param $order |
||
| 320 | * @return mixed |
||
| 321 | * @throws InvalidConfiguration |
||
| 322 | */ |
||
| 323 | public function callFilterPaidOrder(Request $request, $order) |
||
| 337 | |||
| 338 | /** Returns "YES" |
||
| 339 | * @return string |
||
| 340 | */ |
||
| 341 | public function payOrderFromGateOK() |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Runs WebMoneyMerchant::payOrderFromGate($request) when the request from WebMoney Merchant has been received. |
||
| 348 | * @param Request $request |
||
| 349 | * @return mixed |
||
| 350 | */ |
||
| 351 | public function payOrderFromGate(Request $request) |
||
| 400 | } |
||
| 401 |
It seems like you are relying on a variable being defined by an iteration: