Complex classes like Merchant 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 Merchant, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class Merchant extends Entity |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $name; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $siteLanguage; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $status; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $type; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $description; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $address; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | private $contactName; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | private $email; |
||
50 | |||
51 | /** |
||
52 | * @var string |
||
53 | */ |
||
54 | private $phone; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | private $fax; |
||
60 | |||
61 | /** |
||
62 | * @var DateTime |
||
63 | */ |
||
64 | private $registrationDate; |
||
65 | |||
66 | /** |
||
67 | * @var string |
||
68 | */ |
||
69 | private $merchantDomain; |
||
70 | |||
71 | /** |
||
72 | * @var string |
||
73 | */ |
||
74 | private $subdomain; |
||
75 | |||
76 | /** |
||
77 | * @var int |
||
78 | */ |
||
79 | private $agentId; |
||
80 | |||
81 | /** |
||
82 | * @var Agent |
||
83 | */ |
||
84 | private $agent; |
||
85 | |||
86 | /** |
||
87 | * @var int |
||
88 | */ |
||
89 | private $tariffId; |
||
90 | |||
91 | /** |
||
92 | * @var Tariff |
||
93 | */ |
||
94 | private $tariff; |
||
95 | |||
96 | /** |
||
97 | * @var string |
||
98 | */ |
||
99 | private $userIpAccess; |
||
100 | |||
101 | /** |
||
102 | * @var string |
||
103 | */ |
||
104 | private $skype; |
||
105 | |||
106 | /** |
||
107 | * @var string |
||
108 | */ |
||
109 | private $vtIpAccess; |
||
110 | |||
111 | /** |
||
112 | * @var Site[] |
||
113 | */ |
||
114 | private $sites; |
||
115 | |||
116 | /** |
||
117 | * @return string |
||
118 | */ |
||
119 | public function getName(): string |
||
123 | |||
124 | /** |
||
125 | * @param string $name |
||
126 | */ |
||
127 | public function setName(string $name) |
||
131 | |||
132 | /** |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getSiteLanguage(): ?string |
||
139 | |||
140 | /** |
||
141 | * @param string $siteLanguage |
||
142 | */ |
||
143 | public function setSiteLanguage(?string $siteLanguage) |
||
147 | |||
148 | /** |
||
149 | * @return string |
||
150 | */ |
||
151 | public function getStatus(): ?string |
||
155 | |||
156 | /** |
||
157 | * @param string $status |
||
158 | */ |
||
159 | public function setStatus(?string $status) |
||
163 | |||
164 | /** |
||
165 | * @return string |
||
166 | */ |
||
167 | public function getType(): ?string |
||
171 | |||
172 | /** |
||
173 | * @param string $type |
||
174 | */ |
||
175 | public function setType(?string $type) |
||
179 | |||
180 | /** |
||
181 | * @return string |
||
182 | */ |
||
183 | public function getDescription(): ?string |
||
187 | |||
188 | /** |
||
189 | * @param string $description |
||
190 | */ |
||
191 | public function setDescription(?string $description) |
||
195 | |||
196 | /** |
||
197 | * @return string |
||
198 | */ |
||
199 | public function getAddress(): ?string |
||
203 | |||
204 | /** |
||
205 | * @param string $address |
||
206 | */ |
||
207 | public function setAddress(?string $address) |
||
211 | |||
212 | /** |
||
213 | * @return string |
||
214 | */ |
||
215 | public function getContactName(): ?string |
||
219 | |||
220 | /** |
||
221 | * @param string $contactName |
||
222 | */ |
||
223 | public function setContactName(?string $contactName) |
||
227 | |||
228 | /** |
||
229 | * @return string |
||
230 | */ |
||
231 | public function getEmail(): ?string |
||
235 | |||
236 | /** |
||
237 | * @param string $email |
||
238 | */ |
||
239 | public function setEmail(?string $email) |
||
243 | |||
244 | /** |
||
245 | * @return string |
||
246 | */ |
||
247 | public function getPhone(): ?string |
||
251 | |||
252 | /** |
||
253 | * @param string $phone |
||
254 | */ |
||
255 | public function setPhone(?string $phone) |
||
259 | |||
260 | /** |
||
261 | * @return string |
||
262 | */ |
||
263 | public function getFax(): ?string |
||
267 | |||
268 | /** |
||
269 | * @param string $fax |
||
270 | */ |
||
271 | public function setFax(?string $fax) |
||
275 | |||
276 | /** |
||
277 | * @return DateTime |
||
278 | */ |
||
279 | public function getRegistrationDate(): DateTime |
||
283 | |||
284 | /** |
||
285 | * @param DateTime $registrationDate |
||
286 | */ |
||
287 | public function setRegistrationDate(DateTime $registrationDate) |
||
291 | |||
292 | /** |
||
293 | * @return string |
||
294 | */ |
||
295 | public function getMerchantDomain(): ?string |
||
299 | |||
300 | /** |
||
301 | * @param string $merchantDomain |
||
302 | */ |
||
303 | public function setMerchantDomain(?string $merchantDomain) |
||
307 | |||
308 | /** |
||
309 | * @return string |
||
310 | */ |
||
311 | public function getSubdomain(): ?string |
||
315 | |||
316 | /** |
||
317 | * @param string $subdomain |
||
318 | */ |
||
319 | public function setSubdomain(?string $subdomain) |
||
323 | |||
324 | /** |
||
325 | * @return int |
||
326 | */ |
||
327 | public function getAgentId(): int |
||
331 | |||
332 | /** |
||
333 | * @param int $agentId |
||
334 | */ |
||
335 | public function setAgentId(int $agentId) |
||
339 | |||
340 | /** |
||
341 | * @return Agent |
||
342 | */ |
||
343 | public function getAgent(): ?Agent |
||
347 | |||
348 | /** |
||
349 | * @param Agent $agent |
||
350 | */ |
||
351 | public function setAgent(Agent $agent) |
||
355 | |||
356 | /** |
||
357 | * @return int |
||
358 | */ |
||
359 | public function getTariffId(): int |
||
363 | |||
364 | /** |
||
365 | * @param int $tariffId |
||
366 | */ |
||
367 | public function setTariffId(int $tariffId) |
||
371 | |||
372 | /** |
||
373 | * @return string |
||
374 | */ |
||
375 | public function getUserIpAccess(): ?string |
||
379 | |||
380 | /** |
||
381 | * @param string $userIpAccess |
||
382 | */ |
||
383 | public function setUserIpAccess(?string $userIpAccess) |
||
387 | |||
388 | /** |
||
389 | * @return string |
||
390 | */ |
||
391 | public function getVtIpAccess(): ?string |
||
395 | |||
396 | /** |
||
397 | * @param string $vtIpAccess |
||
398 | */ |
||
399 | public function setVtIpAccess(?string $vtIpAccess) |
||
403 | |||
404 | /** |
||
405 | * @return string |
||
406 | */ |
||
407 | public function getSkype(): ?string |
||
411 | |||
412 | /** |
||
413 | * @param string $skype |
||
414 | */ |
||
415 | public function setSkype(?string $skype) |
||
419 | |||
420 | /** |
||
421 | * @return Tariff |
||
422 | */ |
||
423 | public function getTariff(): ?Tariff |
||
427 | |||
428 | /** |
||
429 | * @param Tariff $tariff |
||
430 | */ |
||
431 | public function setTariff(Tariff $tariff) |
||
435 | |||
436 | /** |
||
437 | * @return Site[] |
||
438 | */ |
||
439 | public function getSites(): array |
||
443 | |||
444 | /** |
||
445 | * @param Site[] $sites |
||
446 | */ |
||
447 | public function setSites(array $sites) |
||
451 | } |
||
452 |