Complex classes like ShowPage 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 ShowPage, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class ShowPage extends SymfonyPage implements ShowPageInterface |
||
25 | { |
||
26 | /** |
||
27 | * @var TableAccessorInterface |
||
28 | */ |
||
29 | private $tableAccessor; |
||
30 | |||
31 | /** |
||
32 | * @param Session $session |
||
33 | * @param array $parameters |
||
34 | * @param RouterInterface $router |
||
35 | * @param TableAccessorInterface $tableAccessor |
||
36 | */ |
||
37 | public function __construct( |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function hasCustomer($customerName) |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function hasShippingAddress($customerName, $street, $postcode, $city, $countryName) |
||
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | public function hasBillingAddress($customerName, $street, $postcode, $city, $countryName) |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function hasShipment($shippingDetails) |
||
87 | |||
88 | public function specifyTrackingCode($code) |
||
92 | |||
93 | public function canShipOrder(OrderInterface $order) |
||
97 | |||
98 | public function shipOrder(OrderInterface $order) |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function hasPayment($paymentDetails) |
||
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function canCompleteOrderLastPayment(OrderInterface $order) |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function completeOrderLastPayment(OrderInterface $order) |
||
128 | |||
129 | /** |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function refundOrderLastPayment(OrderInterface $order) |
||
136 | |||
137 | /** |
||
138 | * {@inheritdoc} |
||
139 | */ |
||
140 | public function countItems() |
||
144 | |||
145 | /** |
||
146 | * {@inheritdoc} |
||
147 | */ |
||
148 | public function isProductInTheList(string $productName): bool |
||
170 | |||
171 | /** |
||
172 | * {@inheritdoc} |
||
173 | */ |
||
174 | public function getItemsTotal() |
||
180 | |||
181 | /** |
||
182 | * {@inheritdoc} |
||
183 | */ |
||
184 | public function getTotal() |
||
190 | |||
191 | /** |
||
192 | * {@inheritdoc} |
||
193 | */ |
||
194 | public function getShippingTotal() |
||
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function getTaxTotal() |
||
210 | |||
211 | /** |
||
212 | * {@inheritdoc} |
||
213 | */ |
||
214 | public function hasShippingCharge($shippingCharge) |
||
220 | |||
221 | /** |
||
222 | * {@inheritdoc} |
||
223 | */ |
||
224 | public function getPromotionTotal() |
||
230 | |||
231 | /** |
||
232 | * {@inheritdoc} |
||
233 | */ |
||
234 | public function hasPromotionDiscount($promotionDiscount) |
||
240 | |||
241 | /** |
||
242 | * {@inheritdoc} |
||
243 | */ |
||
244 | public function hasShippingPromotion($promotionName) |
||
248 | |||
249 | /** |
||
250 | * {@inheritdoc} |
||
251 | */ |
||
252 | public function hasTax($tax) |
||
258 | |||
259 | /** |
||
260 | * {@inheritdoc} |
||
261 | */ |
||
262 | public function getItemCode($itemName) |
||
266 | |||
267 | /** |
||
268 | * {@inheritdoc} |
||
269 | */ |
||
270 | public function getItemUnitPrice($itemName) |
||
274 | |||
275 | /** |
||
276 | * {@inheritdoc} |
||
277 | */ |
||
278 | public function getItemDiscountedUnitPrice($itemName) |
||
282 | |||
283 | /** |
||
284 | * {@inheritdoc} |
||
285 | */ |
||
286 | public function getItemQuantity($itemName) |
||
290 | |||
291 | /** |
||
292 | * {@inheritdoc} |
||
293 | */ |
||
294 | public function getItemSubtotal($itemName) |
||
298 | |||
299 | /** |
||
300 | * {@inheritdoc} |
||
301 | */ |
||
302 | public function getItemDiscount($itemName) |
||
306 | |||
307 | /** |
||
308 | * {@inheritdoc} |
||
309 | */ |
||
310 | public function getItemTax($itemName) |
||
314 | |||
315 | /** |
||
316 | * {@inheritdoc} |
||
317 | */ |
||
318 | public function getItemTotal($itemName) |
||
322 | |||
323 | /** |
||
324 | * {@inheritdoc} |
||
325 | */ |
||
326 | public function getPaymentAmount() |
||
332 | |||
333 | /** |
||
334 | * {@inheritdoc} |
||
335 | */ |
||
336 | public function getPaymentsCount() |
||
346 | |||
347 | /** |
||
348 | * {@inheritdoc} |
||
349 | */ |
||
350 | public function getShipmentsCount(): int |
||
360 | |||
361 | /** |
||
362 | * {@inheritdoc} |
||
363 | */ |
||
364 | public function hasCancelButton() |
||
368 | |||
369 | /** |
||
370 | * {@inheritdoc} |
||
371 | */ |
||
372 | public function getOrderState() |
||
376 | |||
377 | /** |
||
378 | * {@inheritdoc} |
||
379 | */ |
||
380 | public function getPaymentState() |
||
384 | |||
385 | /** |
||
386 | * {@inheritdoc} |
||
387 | */ |
||
388 | public function getShippingState() |
||
392 | |||
393 | public function cancelOrder() |
||
397 | |||
398 | public function deleteOrder() |
||
402 | |||
403 | /** |
||
404 | * {@inheritdoc} |
||
405 | */ |
||
406 | public function hasNote($note) |
||
412 | |||
413 | /** |
||
414 | * {@inheritdoc} |
||
415 | */ |
||
416 | public function hasShippingProvinceName($provinceName) |
||
422 | |||
423 | /** |
||
424 | * {@inheritdoc} |
||
425 | */ |
||
426 | public function hasBillingProvinceName($provinceName) |
||
432 | |||
433 | /** |
||
434 | * {@inheritdoc} |
||
435 | */ |
||
436 | public function getIpAddressAssigned() |
||
440 | |||
441 | /** |
||
442 | * {@inheritdoc} |
||
443 | */ |
||
444 | public function getOrderCurrency() |
||
448 | |||
449 | /** |
||
450 | * {@inheritdoc} |
||
451 | */ |
||
452 | public function hasRefundButton() |
||
456 | |||
457 | /** |
||
458 | * {@inheritdoc} |
||
459 | */ |
||
460 | public function getShippingPromotionData() |
||
464 | |||
465 | /** |
||
466 | * {@inheritdoc} |
||
467 | */ |
||
468 | public function getRouteName() |
||
472 | |||
473 | /** |
||
474 | * {@inheritdoc} |
||
475 | */ |
||
476 | protected function getDefinedElements() |
||
502 | |||
503 | /** |
||
504 | * @return TableAccessorInterface |
||
505 | */ |
||
506 | protected function getTableAccessor() |
||
510 | |||
511 | /** |
||
512 | * @param string $elementText |
||
513 | * @param string $customerName |
||
514 | * @param string $street |
||
515 | * @param string $postcode |
||
516 | * @param string $city |
||
517 | * @param string $countryName |
||
518 | * |
||
519 | * @return bool |
||
520 | */ |
||
521 | private function hasAddress($elementText, $customerName, $street, $postcode, $city, $countryName) |
||
530 | |||
531 | /** |
||
532 | * @param string $itemName |
||
533 | * @param string $property |
||
534 | * |
||
535 | * @return string |
||
536 | */ |
||
537 | private function getItemProperty($itemName, $property) |
||
546 | |||
547 | /** |
||
548 | * @param OrderInterface $order |
||
549 | * |
||
550 | * @return NodeElement|null |
||
551 | */ |
||
552 | private function getLastOrderPaymentElement(OrderInterface $order) |
||
561 | |||
562 | /** |
||
563 | * @param OrderInterface $order |
||
564 | * |
||
565 | * @return NodeElement|null |
||
566 | */ |
||
567 | private function getLastOrderShipmentElement(OrderInterface $order) |
||
576 | } |
||
577 |