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($promotionName) |
||
179 | |||
180 | public function getTaxTotal(): string |
||
184 | |||
185 | /** |
||
186 | * {@inheritdoc} |
||
187 | */ |
||
188 | public function hasShippingTotal($price) |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function hasProductUnitPrice(ProductInterface $product, $price) |
||
202 | |||
203 | /** |
||
204 | * {@inheritdoc} |
||
205 | */ |
||
206 | public function hasProductOutOfStockValidationMessage(ProductInterface $product) |
||
212 | |||
213 | /** |
||
214 | * {@inheritdoc} |
||
215 | */ |
||
216 | public function getValidationErrors() |
||
220 | |||
221 | /** |
||
222 | * {@inheritdoc} |
||
223 | */ |
||
224 | public function hasLocale($localeName) |
||
228 | |||
229 | /** |
||
230 | * {@inheritdoc} |
||
231 | */ |
||
232 | public function hasCurrency($currencyCode) |
||
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | */ |
||
240 | public function confirmOrder() |
||
244 | |||
245 | public function changeAddress() |
||
249 | |||
250 | public function changeShippingMethod() |
||
254 | |||
255 | public function changePaymentMethod() |
||
259 | |||
260 | /** |
||
261 | * {@inheritdoc} |
||
262 | */ |
||
263 | public function hasShippingProvinceName($provinceName) |
||
269 | |||
270 | /** |
||
271 | * {@inheritdoc} |
||
272 | */ |
||
273 | public function hasBillingProvinceName($provinceName) |
||
279 | |||
280 | /** |
||
281 | * {@inheritdoc} |
||
282 | */ |
||
283 | public function getShippingPromotionDiscount($promotionName) |
||
287 | |||
288 | /** |
||
289 | * {@inheritdoc} |
||
290 | */ |
||
291 | public function tryToOpen(array $urlParameters = []): void |
||
306 | |||
307 | /** |
||
308 | * {@inheritdoc} |
||
309 | */ |
||
310 | protected function getDefinedElements(): array |
||
336 | |||
337 | /** |
||
338 | * @return NodeElement |
||
339 | */ |
||
340 | private function getProductRowElement(ProductInterface $product) |
||
344 | |||
345 | /** |
||
346 | * @param string $displayedAddress |
||
347 | * |
||
348 | * @return bool |
||
349 | */ |
||
350 | private function isAddressValid($displayedAddress, AddressInterface $address) |
||
364 | |||
365 | /** |
||
366 | * @param string $address |
||
367 | * @param string $addressPart |
||
368 | * |
||
369 | * @return bool |
||
370 | */ |
||
371 | private function hasAddressPart($address, $addressPart, $optional = false) |
||
379 | |||
380 | /** |
||
381 | * @param string $countryCode |
||
382 | * |
||
383 | * @return string |
||
384 | */ |
||
385 | private function getCountryName($countryCode) |
||
389 | |||
390 | private function getPriceFromString(string $price): int |
||
394 | |||
395 | /** |
||
396 | * @param string $total |
||
397 | * |
||
398 | * @return int |
||
399 | */ |
||
400 | private function getTotalFromString($total) |
||
406 | |||
407 | /** |
||
408 | * @param string $total |
||
409 | * |
||
410 | * @return int |
||
411 | */ |
||
412 | private function getBaseTotalFromString($total) |
||
418 | } |
||
419 |