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 |
||
25 | class ShowPage extends SymfonyPage implements ShowPageInterface |
||
26 | { |
||
27 | /** @var TableAccessorInterface */ |
||
28 | private $tableAccessor; |
||
29 | |||
30 | /** @var MoneyFormatterInterface */ |
||
31 | private $moneyFormatter; |
||
32 | |||
33 | public function __construct( |
||
34 | Session $session, |
||
35 | $minkParameters, |
||
36 | RouterInterface $router, |
||
37 | TableAccessorInterface $tableAccessor, |
||
38 | MoneyFormatterInterface $moneyFormatter |
||
39 | ) { |
||
40 | parent::__construct($session, $minkParameters, $router); |
||
41 | |||
42 | $this->tableAccessor = $tableAccessor; |
||
43 | $this->moneyFormatter = $moneyFormatter; |
||
44 | } |
||
45 | |||
46 | public function hasCustomer(string $customerName): bool |
||
47 | { |
||
48 | $customerText = $this->getElement('customer')->getText(); |
||
49 | |||
50 | return stripos($customerText, $customerName) !== false; |
||
51 | } |
||
52 | |||
53 | public function hasShippingAddress(string $customerName, string $street, string $postcode, string $city, string $countryName): bool |
||
54 | { |
||
55 | $shippingAddressText = $this->getElement('shipping_address')->getText(); |
||
56 | |||
57 | return $this->hasAddress($shippingAddressText, $customerName, $street, $postcode, $city, $countryName); |
||
58 | } |
||
59 | |||
60 | public function hasShippingAddressVisible(): bool |
||
61 | { |
||
62 | try { |
||
63 | $this->getElement('shipping_address'); |
||
64 | } catch (ElementNotFoundException $exception) { |
||
|
|||
65 | return false; |
||
66 | } |
||
67 | |||
68 | return true; |
||
69 | } |
||
70 | |||
71 | public function hasBillingAddress(string $customerName, string $street, string $postcode, string $city, string $countryName): bool |
||
77 | |||
78 | public function hasShipment(string $shippingDetails): bool |
||
79 | { |
||
80 | $shipmentsText = $this->getElement('shipments')->getText(); |
||
81 | |||
84 | |||
85 | public function specifyTrackingCode(string $code): void |
||
89 | |||
90 | public function canShipOrder(OrderInterface $order): bool |
||
94 | |||
95 | public function shipOrder(OrderInterface $order): void |
||
99 | |||
100 | public function hasPayment(string $paymentDetails): bool |
||
106 | |||
107 | public function canCompleteOrderLastPayment(OrderInterface $order): bool |
||
111 | |||
112 | public function completeOrderLastPayment(OrderInterface $order): void |
||
116 | |||
117 | public function refundOrderLastPayment(OrderInterface $order): void |
||
121 | |||
122 | public function countItems(): int |
||
126 | |||
127 | public function isProductInTheList(string $productName): bool |
||
149 | |||
150 | public function getItemsTotal(): string |
||
156 | |||
157 | public function getTotal(): string |
||
163 | |||
164 | public function getShippingTotal(): string |
||
170 | |||
171 | public function getTaxTotal(): string |
||
177 | |||
178 | public function hasShippingCharge(string $shippingCharge): bool |
||
188 | |||
189 | public function getOrderPromotionTotal(): string |
||
195 | |||
196 | public function hasPromotionDiscount(string $promotionName, string $promotionAmount): bool |
||
202 | |||
203 | public function hasTax(string $tax): bool |
||
209 | |||
210 | public function getItemCode(string $itemName): string |
||
214 | |||
215 | public function getItemUnitPrice(string $itemName): string |
||
219 | |||
220 | public function getItemDiscountedUnitPrice(string $itemName): string |
||
224 | |||
225 | public function getItemOrderDiscount(string $itemName): string |
||
229 | |||
230 | public function getItemQuantity(string $itemName): string |
||
234 | |||
235 | public function getItemSubtotal(string $itemName): string |
||
239 | |||
240 | public function getItemDiscount(string $itemName): string |
||
244 | |||
245 | public function getItemTax(string $itemName): string |
||
249 | |||
250 | public function getItemTaxIncludedInPrice(string $itemName): string |
||
254 | |||
255 | public function getItemTotal(string $itemName): string |
||
259 | |||
260 | public function getPaymentAmount(): string |
||
266 | |||
267 | public function getPaymentsCount(): int |
||
277 | |||
278 | public function getShipmentsCount(): int |
||
288 | |||
289 | public function hasCancelButton(): bool |
||
293 | |||
294 | public function getOrderState(): string |
||
298 | |||
299 | public function getPaymentState(): string |
||
303 | |||
304 | public function getShippingState(): string |
||
308 | |||
309 | public function cancelOrder(): void |
||
313 | |||
314 | public function deleteOrder(): void |
||
318 | |||
319 | public function hasNote(string $note): bool |
||
325 | |||
326 | public function hasShippingProvinceName(string $provinceName): bool |
||
332 | |||
333 | public function hasBillingProvinceName(string $provinceName): bool |
||
339 | |||
340 | public function getIpAddressAssigned(): string |
||
344 | |||
345 | public function getOrderCurrency(): string |
||
349 | |||
350 | public function hasRefundButton(): bool |
||
354 | |||
355 | public function getShippingPromotionData(): string |
||
359 | |||
360 | public function getRouteName(): string |
||
364 | |||
365 | public function hasInformationAboutNoPayment(): bool |
||
369 | |||
370 | public function resendOrderConfirmationEmail(): void |
||
374 | |||
375 | public function resendShipmentConfirmationEmail(): void |
||
379 | |||
380 | protected function getDefinedElements(): array |
||
409 | |||
410 | protected function getTableAccessor(): TableAccessorInterface |
||
414 | |||
415 | private function hasAddress(string $elementText, string $customerName, string $street, string $postcode, string $city, string $countryName): bool |
||
424 | |||
425 | private function getItemProperty(string $itemName, string $property): string |
||
434 | |||
435 | private function getRowWithItem(string $itemName): ?NodeElement |
||
439 | |||
440 | private function getLastOrderPaymentElement(OrderInterface $order): ?NodeElement |
||
449 | |||
450 | private function getLastOrderShipmentElement(OrderInterface $order): ?NodeElement |
||
459 | |||
460 | private function getFormattedMoney(int $orderPromotionTotal): string |
||
464 | } |
||
465 |
Scrutinizer analyzes your
composer.json
/composer.lock
file if available to determine the classes, and functions that are defined by your dependencies.It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.