Complex classes like CompletePage 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 CompletePage, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | class CompletePage extends SymfonyPage implements CompletePageInterface |
||
| 28 | { |
||
| 29 | /** @var TableAccessorInterface */ |
||
| 30 | private $tableAccessor; |
||
| 31 | |||
| 32 | public function __construct( |
||
| 42 | |||
| 43 | /** |
||
| 44 | * {@inheritdoc} |
||
| 45 | */ |
||
| 46 | public function getRouteName(): string |
||
| 50 | |||
| 51 | /** |
||
| 52 | * {@inheritdoc} |
||
| 53 | */ |
||
| 54 | public function hasItemWithProductAndQuantity($productName, $quantity) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * {@inheritdoc} |
||
| 69 | */ |
||
| 70 | public function hasShippingAddress(AddressInterface $address) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | public function hasBillingAddress(AddressInterface $address) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | public function hasShippingMethod(ShippingMethodInterface $shippingMethod) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * {@inheritdoc} |
||
| 101 | */ |
||
| 102 | public function getPaymentMethodName() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * {@inheritdoc} |
||
| 109 | */ |
||
| 110 | public function hasPaymentMethod() |
||
| 114 | |||
| 115 | /** |
||
| 116 | * {@inheritdoc} |
||
| 117 | */ |
||
| 118 | public function hasProductDiscountedUnitPriceBy(ProductInterface $product, $amount) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * {@inheritdoc} |
||
| 130 | */ |
||
| 131 | public function hasOrderTotal($total) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | */ |
||
| 143 | public function getBaseCurrencyOrderTotal() |
||
| 147 | |||
| 148 | /** |
||
| 149 | * {@inheritdoc} |
||
| 150 | */ |
||
| 151 | public function addNotes($notes) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritdoc} |
||
| 158 | */ |
||
| 159 | public function hasPromotionTotal($promotionTotal) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * {@inheritdoc} |
||
| 166 | */ |
||
| 167 | public function hasPromotion($promotionName) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | public function hasShippingPromotion(string $promotionName): bool |
||
| 182 | |||
| 183 | public function getTaxTotal(): string |
||
| 187 | |||
| 188 | public function getShippingTotal(): string |
||
| 192 | |||
| 193 | public function hasShippingTotal(): bool |
||
| 197 | |||
| 198 | /** |
||
| 199 | * {@inheritdoc} |
||
| 200 | */ |
||
| 201 | public function hasProductUnitPrice(ProductInterface $product, $price) |
||
| 207 | |||
| 208 | /** |
||
| 209 | * {@inheritdoc} |
||
| 210 | */ |
||
| 211 | public function hasProductOutOfStockValidationMessage(ProductInterface $product) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * {@inheritdoc} |
||
| 220 | */ |
||
| 221 | public function getValidationErrors() |
||
| 225 | |||
| 226 | /** |
||
| 227 | * {@inheritdoc} |
||
| 228 | */ |
||
| 229 | public function hasLocale($localeName) |
||
| 233 | |||
| 234 | /** |
||
| 235 | * {@inheritdoc} |
||
| 236 | */ |
||
| 237 | public function hasCurrency($currencyCode) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * {@inheritdoc} |
||
| 244 | */ |
||
| 245 | public function confirmOrder() |
||
| 249 | |||
| 250 | public function changeAddress() |
||
| 254 | |||
| 255 | public function changeShippingMethod() |
||
| 259 | |||
| 260 | public function changePaymentMethod() |
||
| 264 | |||
| 265 | /** |
||
| 266 | * {@inheritdoc} |
||
| 267 | */ |
||
| 268 | public function hasShippingProvinceName($provinceName) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * {@inheritdoc} |
||
| 277 | */ |
||
| 278 | public function hasBillingProvinceName($provinceName) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * {@inheritdoc} |
||
| 287 | */ |
||
| 288 | public function getShippingPromotionDiscount($promotionName) |
||
| 292 | |||
| 293 | /** |
||
| 294 | * {@inheritdoc} |
||
| 295 | */ |
||
| 296 | public function tryToOpen(array $urlParameters = []): void |
||
| 311 | |||
| 312 | public function hasShippingPromotionWithDiscount(string $promotionName, string $discount): bool |
||
| 321 | |||
| 322 | public function hasOrderPromotion(string $promotionName): bool |
||
| 329 | |||
| 330 | /** |
||
| 331 | * {@inheritdoc} |
||
| 332 | */ |
||
| 333 | protected function getDefinedElements(): array |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return NodeElement |
||
| 364 | */ |
||
| 365 | private function getProductRowElement(ProductInterface $product) |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @param string $displayedAddress |
||
| 372 | * |
||
| 373 | * @return bool |
||
| 374 | */ |
||
| 375 | private function isAddressValid($displayedAddress, AddressInterface $address) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @param string $address |
||
| 392 | * @param string $addressPart |
||
| 393 | * |
||
| 394 | * @return bool |
||
| 395 | */ |
||
| 396 | private function hasAddressPart($address, $addressPart, $optional = false) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @param string $countryCode |
||
| 407 | * |
||
| 408 | * @return string |
||
| 409 | */ |
||
| 410 | private function getCountryName($countryCode) |
||
| 414 | |||
| 415 | private function getPriceFromString(string $price): int |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @param string $total |
||
| 422 | * |
||
| 423 | * @return int |
||
| 424 | */ |
||
| 425 | private function getTotalFromString($total) |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @param string $total |
||
| 434 | * |
||
| 435 | * @return int |
||
| 436 | */ |
||
| 437 | private function getBaseTotalFromString($total) |
||
| 443 | } |
||
| 444 |