Complex classes like Product 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 Product, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class Product extends Entity |
||
8 | { |
||
9 | const TYPE_FREE_PRICE = 'FREE_PRICE'; |
||
10 | const TYPE_FIXED_PRICE = 'FIXED_PRICE'; |
||
11 | const TYPE_SUBSCRIBE = 'SUBSCRIBE'; |
||
12 | |||
13 | private $status; |
||
14 | private $type; |
||
15 | private $price; |
||
16 | private $description; |
||
17 | private $allowRandomPrice; |
||
18 | private $fields; |
||
19 | private $currencyId; |
||
20 | private $currency; |
||
21 | private $siteId; |
||
22 | private $site; |
||
23 | private $notifyUrl; |
||
24 | private $workThrough; |
||
25 | private $confirmPaymentType; |
||
26 | private $notifyEmail; |
||
27 | private $messengerNotifyUrl; |
||
28 | private $supportEmail; |
||
29 | private $supportPhone; |
||
30 | private $accessUrl; |
||
31 | private $secretWord; |
||
32 | private $allowRebill; |
||
33 | private $UUID; |
||
34 | |||
35 | /** |
||
36 | * @var Payment[] |
||
37 | */ |
||
38 | private $payments; |
||
39 | |||
40 | |||
41 | public function getType(): ?string |
||
45 | |||
46 | public function setType(?string $type): void |
||
50 | |||
51 | public function getPrice(): ?float |
||
55 | |||
56 | public function setPrice(?float $price): void |
||
60 | |||
61 | public function getDescription(): ?string |
||
65 | |||
66 | public function setDescription(?string $description): void |
||
70 | |||
71 | public function getAllowRandomPrice(): bool |
||
75 | |||
76 | public function setAllowRandomPrice(bool $allowRandomPrice): void |
||
80 | |||
81 | public function getFields(): ?string |
||
85 | |||
86 | public function setFields(?string $fields): void |
||
90 | |||
91 | public function getCurrencyId(): ?int |
||
95 | |||
96 | public function setCurrencyId(?int $currencyId): void |
||
100 | |||
101 | public function getSiteId(): ?int |
||
105 | |||
106 | public function setSiteId(?int $siteId): void |
||
110 | |||
111 | public function getSite(): ?Site |
||
115 | |||
116 | public function setSite(?Site $site): void |
||
120 | |||
121 | /** |
||
122 | * @return Payment[] |
||
123 | */ |
||
124 | public function getPayments(): array |
||
128 | |||
129 | /** |
||
130 | * @param Payment[] $payments |
||
131 | */ |
||
132 | public function setPayments(array $payments) |
||
136 | |||
137 | public function getStatus(): ?string |
||
141 | |||
142 | public function setStatus(?string $status) |
||
146 | |||
147 | public function getNotifyUrl(): ?string |
||
151 | |||
152 | public function setNotifyUrl(?string $notifyUrl) |
||
156 | |||
157 | public function getWorkThrough():?string |
||
161 | |||
162 | public function setWorkThrough(?string $workThrough) |
||
166 | |||
167 | public function getConfirmPaymentType(): string |
||
171 | |||
172 | public function setConfirmPaymentType(string $confirmPaymentType) |
||
176 | |||
177 | public function getNotifyEmail(): ?string |
||
181 | |||
182 | public function setNotifyEmail(?string $notifyEmail) |
||
186 | |||
187 | public function getMessengerNotifyUrl(): ?string |
||
191 | |||
192 | public function setMessengerNotifyUrl(?string $messengerNotifyUrl) |
||
196 | |||
197 | public function getSupportEmail(): ?string |
||
201 | |||
202 | public function setSupportEmail(?string $supportEmail) |
||
206 | |||
207 | public function getSupportPhone(): ?string |
||
211 | |||
212 | public function setSupportPhone(?string $supportPhone) |
||
216 | |||
217 | public function getAccessUrl(): ?string |
||
221 | |||
222 | public function setAccessUrl(?string $accessUrl) |
||
226 | |||
227 | public function getSecretWord(): ?string |
||
231 | |||
232 | public function setSecretWord(?string $secretWord) |
||
236 | |||
237 | public function getAllowRebill():?int |
||
241 | |||
242 | public function setAllowRebill(?int $allowRebill) |
||
246 | |||
247 | public function getUUID(): ?string |
||
251 | |||
252 | public function setUUID(?string $UUID) |
||
256 | |||
257 | public function getCurrency(): ?Currency |
||
261 | |||
262 | public function setCurrency(?Currency $currency) |
||
266 | } |
||
267 |