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 |
||
| 28 | class CompletePage extends SymfonyPage implements CompletePageInterface |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * @var TableAccessorInterface |
||
| 32 | */ |
||
| 33 | private $tableAccessor; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param Session $session |
||
| 37 | * @param array $parameters |
||
| 38 | * @param RouterInterface $router |
||
| 39 | * @param TableAccessorInterface $tableAccessor |
||
| 40 | */ |
||
| 41 | public function __construct( |
||
| 51 | |||
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | public function getRouteName() |
||
| 60 | |||
| 61 | /** |
||
| 62 | * {@inheritdoc} |
||
| 63 | */ |
||
| 64 | public function hasItemWithProductAndQuantity($productName, $quantity) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | public function hasShippingAddress(AddressInterface $address) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * {@inheritdoc} |
||
| 89 | */ |
||
| 90 | public function hasBillingAddress(AddressInterface $address) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * {@inheritdoc} |
||
| 99 | */ |
||
| 100 | public function hasShippingMethod(ShippingMethodInterface $shippingMethod) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * {@inheritdoc} |
||
| 111 | */ |
||
| 112 | public function hasPaymentMethod(PaymentMethodInterface $paymentMethod) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * {@inheritdoc} |
||
| 123 | */ |
||
| 124 | public function hasProductDiscountedUnitPriceBy(ProductInterface $product, $amount) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * {@inheritdoc} |
||
| 136 | */ |
||
| 137 | public function hasOrderTotal($total) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * {@inheritdoc} |
||
| 148 | */ |
||
| 149 | public function getBaseCurrencyOrderTotal() |
||
| 153 | |||
| 154 | /** |
||
| 155 | * {@inheritdoc} |
||
| 156 | */ |
||
| 157 | public function addNotes($notes) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * {@inheritdoc} |
||
| 164 | */ |
||
| 165 | public function hasPromotionTotal($promotionTotal) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * {@inheritdoc} |
||
| 172 | */ |
||
| 173 | public function hasPromotion($promotionName) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * {@inheritdoc} |
||
| 180 | */ |
||
| 181 | public function hasTaxTotal($taxTotal) |
||
| 185 | |||
| 186 | /** |
||
| 187 | * {@inheritdoc} |
||
| 188 | */ |
||
| 189 | public function hasShippingTotal($price) |
||
| 193 | |||
| 194 | /** |
||
| 195 | * {@inheritdoc} |
||
| 196 | */ |
||
| 197 | public function hasProductUnitPrice(ProductInterface $product, $price) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | public function hasProductOutOfStockValidationMessage(ProductInterface $product) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * {@inheritdoc} |
||
| 216 | */ |
||
| 217 | public function hasLocale($localeName) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * {@inheritdoc} |
||
| 224 | */ |
||
| 225 | public function hasCurrency($currencyCode) |
||
| 229 | |||
| 230 | public function confirmOrder() |
||
| 234 | |||
| 235 | public function changeAddress() |
||
| 239 | |||
| 240 | public function changeShippingMethod() |
||
| 244 | |||
| 245 | public function changePaymentMethod() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * {@inheritdoc} |
||
| 252 | */ |
||
| 253 | public function hasShippingProvinceName($provinceName) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * {@inheritdoc} |
||
| 262 | */ |
||
| 263 | public function hasBillingProvinceName($provinceName) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * {@inheritdoc} |
||
| 272 | */ |
||
| 273 | protected function getDefinedElements() |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param ProductInterface $product |
||
| 300 | * |
||
| 301 | * @return NodeElement |
||
| 302 | */ |
||
| 303 | private function getProductRowElement(ProductInterface $product) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @param string $displayedAddress |
||
| 310 | * @param AddressInterface $address |
||
| 311 | * |
||
| 312 | * @return bool |
||
| 313 | */ |
||
| 314 | private function isAddressValid($displayedAddress, AddressInterface $address) |
||
| 328 | |||
| 329 | /** |
||
| 330 | * @param string $address |
||
| 331 | * @param string $addressPart |
||
| 332 | * |
||
| 333 | * @return bool |
||
| 334 | */ |
||
| 335 | private function hasAddressPart($address, $addressPart, $optional = false) |
||
| 343 | |||
| 344 | /** |
||
| 345 | * @param string $countryCode |
||
| 346 | * |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | private function getCountryName($countryCode) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @param string $price |
||
| 356 | * |
||
| 357 | * @return int |
||
| 358 | */ |
||
| 359 | private function getPriceFromString($price) |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @param string $total |
||
| 366 | * |
||
| 367 | * @return int |
||
| 368 | */ |
||
| 369 | private function getTotalFromString($total) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @param string $total |
||
| 378 | * |
||
| 379 | * @return int |
||
| 380 | */ |
||
| 381 | private function getBaseTotalFromString($total) |
||
| 387 | } |
||
| 388 |