Complex classes like AbstractPurchaseRequest 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 AbstractPurchaseRequest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | abstract class AbstractPurchaseRequest extends AbstractSignatureRequest |
||
16 | { |
||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | */ |
||
20 | public function initialize(array $parameters = []) |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | * @throws \Omnipay\Common\Exception\InvalidRequestException |
||
47 | */ |
||
48 | public function getData(): array |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function sendData($data): PurchaseResponse |
||
66 | |||
67 | /** |
||
68 | * Trả giao diện ngôn ngữ khách dùng để thanh toán. |
||
69 | * |
||
70 | * @return null|string |
||
71 | */ |
||
72 | public function getVpcLocale(): ?string |
||
76 | |||
77 | /** |
||
78 | * Thiết lập giao diện ngôn ngữ khách dùng để thanh toán. |
||
79 | * |
||
80 | * @param null|string $locale |
||
81 | * @return $this |
||
82 | */ |
||
83 | public function setVpcLocale(?string $locale) |
||
87 | |||
88 | /** |
||
89 | * Trả về đường dẫn thanh toán tại hệ thống của bạn mà khách đã dùng để thanh toán. |
||
90 | * Nếu không thiết lập hệ thống sẽ tự động lấy đường dẫn của khách truy vấn hệ thống hiện tại, đối với CLI mode sẽ là empty. |
||
91 | * |
||
92 | * @return null|string |
||
93 | */ |
||
94 | public function getAgainLink(): ?string |
||
98 | |||
99 | /** |
||
100 | * Thiết lập đường dẫn thanh toán tại hệ thống của bạn mà khách đã dùng để thanh toán. |
||
101 | * |
||
102 | * @param null|string $link |
||
103 | * @return $this |
||
104 | */ |
||
105 | public function setAgainLink(?string $link) |
||
109 | |||
110 | /** |
||
111 | * Trả về tiêu đề hiển thị tại OnePay khi thanh toán. |
||
112 | * |
||
113 | * @return null|string |
||
114 | */ |
||
115 | public function getTitle(): ?string |
||
119 | |||
120 | /** |
||
121 | * Thiết lập tiêu đề hiển thị tại OnePay khi thanh toán. |
||
122 | * |
||
123 | * @param null|string $title |
||
124 | * @return $this |
||
125 | */ |
||
126 | public function setTitle(?string $title) |
||
130 | |||
131 | /** |
||
132 | * Phương thức ánh xạ của [[getClientIp()]]. |
||
133 | * |
||
134 | * @return null|string |
||
135 | * @see getClientIp |
||
136 | */ |
||
137 | public function getVpcTicketNo(): ?string |
||
141 | |||
142 | /** |
||
143 | * Phương thức ánh xạ của [[setClientIp()]]. |
||
144 | * |
||
145 | * @param null|string $ticketNo |
||
146 | * @return $this |
||
147 | * @see setClientIp |
||
148 | */ |
||
149 | public function setVpcTicketNo(?string $ticketNo) |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public function getClientIp(): ?string |
||
161 | |||
162 | /** |
||
163 | * {@inheritdoc} |
||
164 | */ |
||
165 | public function setClientIp($value) |
||
169 | |||
170 | /** |
||
171 | * Phương thức ánh xạ của [[getAmount()]]. |
||
172 | * |
||
173 | * @return null|string |
||
174 | * @see getAmount |
||
175 | */ |
||
176 | public function getVpcAmount(): ?string |
||
180 | |||
181 | /** |
||
182 | * Phương thức ánh xạ của [[setAmount()]]. |
||
183 | * |
||
184 | * @param null|string $amount |
||
185 | * @return $this |
||
186 | * @see setAmount |
||
187 | */ |
||
188 | public function setVpcAmount(?string $amount) |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function getAmount(): ?string |
||
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function setAmount($value) |
||
208 | |||
209 | /** |
||
210 | * Trả về thông tin đơn hàng. |
||
211 | * |
||
212 | * @return null|string |
||
213 | */ |
||
214 | public function getVpcOrderInfo(): ?string |
||
218 | |||
219 | /** |
||
220 | * Thiết lập thông tin đơn hàng. |
||
221 | * |
||
222 | * @param null|string $info |
||
223 | * @return $this |
||
224 | */ |
||
225 | public function setVpcOrderInfo(?string $info) |
||
229 | |||
230 | /** |
||
231 | * Trả về mã đơn hàng cần thanh toán. |
||
232 | * |
||
233 | * @return null|string |
||
234 | */ |
||
235 | public function getVpcMerchTxnRef(): ?string |
||
239 | |||
240 | /** |
||
241 | * Thiết lập mã đơn hàng cần thanh toán tại hệ thống của bạn. |
||
242 | * |
||
243 | * @param null|string $ref |
||
244 | * @return $this |
||
245 | */ |
||
246 | public function setVpcMerchTxnRef(?string $ref) |
||
250 | |||
251 | /** |
||
252 | * Trả về đơn vị tiền tệ sử dụng thanh toán của khách. |
||
253 | * |
||
254 | * @return null|string |
||
255 | */ |
||
256 | public function getVpcCurrency(): ?string |
||
260 | |||
261 | /** |
||
262 | * Thiết lập đơn vị tiền tệ sử dụng thanh toán của khách. |
||
263 | * |
||
264 | * @param null|string $currency |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function setVpcCurrency(?string $currency) |
||
271 | |||
272 | /** |
||
273 | * {@inheritdoc} |
||
274 | */ |
||
275 | public function getCurrency(): ?string |
||
279 | |||
280 | /** |
||
281 | * {@inheritdoc} |
||
282 | */ |
||
283 | public function setCurrency($value) |
||
287 | |||
288 | /** |
||
289 | * Trả về số điện thoại khách hàng. |
||
290 | * |
||
291 | * @return null|string |
||
292 | */ |
||
293 | public function getVpcCustomerPhone(): ?string |
||
297 | |||
298 | /** |
||
299 | * Thiết lập số điện thoại khách hàng. |
||
300 | * |
||
301 | * @param null|string $phone |
||
302 | * @return $this |
||
303 | */ |
||
304 | public function setVpcCustomerPhone(?string $phone) |
||
308 | |||
309 | /** |
||
310 | * Trả về id khách hàng. |
||
311 | * |
||
312 | * @return null|string |
||
313 | */ |
||
314 | public function getVpcCustomerId(): ?string |
||
318 | |||
319 | /** |
||
320 | * Thiết lập id khách hàng. |
||
321 | * |
||
322 | * @param null|string $id |
||
323 | * @return $this |
||
324 | */ |
||
325 | public function setVpcCustomerId(?string $id) |
||
329 | |||
330 | /** |
||
331 | * Phương thức ánh xạ của [[getReturnUrl()]]. |
||
332 | * Trả về đường dẫn tại hệ thống của bạn sẽ redirect khách về sau khi thanh toán. |
||
333 | * |
||
334 | * @return null|string |
||
335 | * @see getReturnUrl |
||
336 | */ |
||
337 | public function getVpcReturnURL(): ?string |
||
341 | |||
342 | /** |
||
343 | * Phương thức ánh xạ của [[setReturnUrl()]]. |
||
344 | * |
||
345 | * @param null|string $url |
||
346 | * @return $this |
||
347 | * @see setReturnUrl |
||
348 | */ |
||
349 | public function setVpcReturnURL(?string $url) |
||
353 | |||
354 | /** |
||
355 | * {@inheritdoc} |
||
356 | */ |
||
357 | public function getReturnUrl(): ?string |
||
361 | |||
362 | /** |
||
363 | * {@inheritdoc} |
||
364 | */ |
||
365 | public function setReturnUrl($value) |
||
369 | |||
370 | /** |
||
371 | * Trả về email khách hàng. |
||
372 | * |
||
373 | * @return null|string |
||
374 | */ |
||
375 | public function getVpcCustomerEmail(): ?string |
||
379 | |||
380 | /** |
||
381 | * Thiết lập email khách hàng. |
||
382 | * |
||
383 | * @param null|string $email |
||
384 | * @return $this |
||
385 | */ |
||
386 | public function setVpcCustomerEmail(?string $email) |
||
390 | |||
391 | /** |
||
392 | * {@inheritdoc} |
||
393 | */ |
||
394 | protected function getSignatureParameters(): array |
||
415 | } |
||
416 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: