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($productName) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * {@inheritdoc} |
||
| 164 | */ |
||
| 165 | public function getItemsTotal() |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | public function getTotal() |
||
| 181 | |||
| 182 | /** |
||
| 183 | * {@inheritdoc} |
||
| 184 | */ |
||
| 185 | public function getShippingTotal() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | */ |
||
| 195 | public function getTaxTotal() |
||
| 201 | |||
| 202 | /** |
||
| 203 | * {@inheritdoc} |
||
| 204 | */ |
||
| 205 | public function hasShippingCharge($shippingCharge) |
||
| 211 | |||
| 212 | /** |
||
| 213 | * {@inheritdoc} |
||
| 214 | */ |
||
| 215 | public function getPromotionTotal() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * {@inheritdoc} |
||
| 224 | */ |
||
| 225 | public function hasPromotionDiscount($promotionDiscount) |
||
| 231 | |||
| 232 | /** |
||
| 233 | * {@inheritdoc} |
||
| 234 | */ |
||
| 235 | public function hasShippingPromotion($promotionName) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * {@inheritdoc} |
||
| 242 | */ |
||
| 243 | public function hasTax($tax) |
||
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritdoc} |
||
| 252 | */ |
||
| 253 | public function getItemCode($itemName) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * {@inheritdoc} |
||
| 260 | */ |
||
| 261 | public function getItemUnitPrice($itemName) |
||
| 265 | |||
| 266 | /** |
||
| 267 | * {@inheritdoc} |
||
| 268 | */ |
||
| 269 | public function getItemDiscountedUnitPrice($itemName) |
||
| 273 | |||
| 274 | /** |
||
| 275 | * {@inheritdoc} |
||
| 276 | */ |
||
| 277 | public function getItemQuantity($itemName) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * {@inheritdoc} |
||
| 284 | */ |
||
| 285 | public function getItemSubtotal($itemName) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * {@inheritdoc} |
||
| 292 | */ |
||
| 293 | public function getItemDiscount($itemName) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * {@inheritdoc} |
||
| 300 | */ |
||
| 301 | public function getItemTax($itemName) |
||
| 305 | |||
| 306 | /** |
||
| 307 | * {@inheritdoc} |
||
| 308 | */ |
||
| 309 | public function getItemTotal($itemName) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * {@inheritdoc} |
||
| 316 | */ |
||
| 317 | public function getPaymentAmount() |
||
| 323 | |||
| 324 | /** |
||
| 325 | * {@inheritdoc} |
||
| 326 | */ |
||
| 327 | public function getPaymentsCount() |
||
| 337 | |||
| 338 | /** |
||
| 339 | * {@inheritdoc} |
||
| 340 | */ |
||
| 341 | public function getShipmentsCount(): int |
||
| 351 | |||
| 352 | /** |
||
| 353 | * {@inheritdoc} |
||
| 354 | */ |
||
| 355 | public function hasCancelButton() |
||
| 359 | |||
| 360 | /** |
||
| 361 | * {@inheritdoc} |
||
| 362 | */ |
||
| 363 | public function getOrderState() |
||
| 367 | |||
| 368 | /** |
||
| 369 | * {@inheritdoc} |
||
| 370 | */ |
||
| 371 | public function getPaymentState() |
||
| 375 | |||
| 376 | /** |
||
| 377 | * {@inheritdoc} |
||
| 378 | */ |
||
| 379 | public function getShippingState() |
||
| 383 | |||
| 384 | public function cancelOrder() |
||
| 388 | |||
| 389 | public function deleteOrder() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * {@inheritdoc} |
||
| 396 | */ |
||
| 397 | public function hasNote($note) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * {@inheritdoc} |
||
| 406 | */ |
||
| 407 | public function hasShippingProvinceName($provinceName) |
||
| 413 | |||
| 414 | /** |
||
| 415 | * {@inheritdoc} |
||
| 416 | */ |
||
| 417 | public function hasBillingProvinceName($provinceName) |
||
| 423 | |||
| 424 | /** |
||
| 425 | * {@inheritdoc} |
||
| 426 | */ |
||
| 427 | public function getIpAddressAssigned() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * {@inheritdoc} |
||
| 434 | */ |
||
| 435 | public function getOrderCurrency() |
||
| 439 | |||
| 440 | /** |
||
| 441 | * {@inheritdoc} |
||
| 442 | */ |
||
| 443 | public function hasRefundButton() |
||
| 447 | |||
| 448 | /** |
||
| 449 | * {@inheritdoc} |
||
| 450 | */ |
||
| 451 | public function getShippingPromotionData() |
||
| 455 | |||
| 456 | /** |
||
| 457 | * {@inheritdoc} |
||
| 458 | */ |
||
| 459 | public function getRouteName() |
||
| 463 | |||
| 464 | /** |
||
| 465 | * {@inheritdoc} |
||
| 466 | */ |
||
| 467 | protected function getDefinedElements() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * @return TableAccessorInterface |
||
| 496 | */ |
||
| 497 | protected function getTableAccessor() |
||
| 501 | |||
| 502 | /** |
||
| 503 | * @param string $elementText |
||
| 504 | * @param string $customerName |
||
| 505 | * @param string $street |
||
| 506 | * @param string $postcode |
||
| 507 | * @param string $city |
||
| 508 | * @param string $countryName |
||
| 509 | * |
||
| 510 | * @return bool |
||
| 511 | */ |
||
| 512 | private function hasAddress($elementText, $customerName, $street, $postcode, $city, $countryName) |
||
| 521 | |||
| 522 | /** |
||
| 523 | * @param string $itemName |
||
| 524 | * @param string $property |
||
| 525 | * |
||
| 526 | * @return string |
||
| 527 | */ |
||
| 528 | private function getItemProperty($itemName, $property) |
||
| 537 | |||
| 538 | /** |
||
| 539 | * @param OrderInterface $order |
||
| 540 | * |
||
| 541 | * @return NodeElement|null |
||
| 542 | */ |
||
| 543 | private function getLastOrderPaymentElement(OrderInterface $order) |
||
| 552 | |||
| 553 | /** |
||
| 554 | * @param OrderInterface $order |
||
| 555 | * |
||
| 556 | * @return NodeElement|null |
||
| 557 | */ |
||
| 558 | private function getLastOrderShipmentElement(OrderInterface $order) |
||
| 567 | } |
||
| 568 |