Complex classes like ShowResponse 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 ShowResponse, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class ShowResponse implements ApiResponse |
||
18 | { |
||
19 | /** |
||
20 | * Only available with message/rfc2822. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | private $recipient; |
||
25 | |||
26 | /** |
||
27 | * Only available with message/rfc2822. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | private $bodyMime; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | private $recipients; |
||
37 | |||
38 | /** |
||
39 | * @var string |
||
40 | */ |
||
41 | private $sender; |
||
42 | |||
43 | /** |
||
44 | * @var string |
||
45 | */ |
||
46 | private $from; |
||
47 | |||
48 | /** |
||
49 | * @var string |
||
50 | */ |
||
51 | private $subject; |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | private $bodyPlain; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | private $strippedText; |
||
62 | |||
63 | /** |
||
64 | * @var string |
||
65 | */ |
||
66 | private $strippedSignature; |
||
67 | |||
68 | /** |
||
69 | * @var string |
||
70 | */ |
||
71 | private $bodyHtml; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | */ |
||
76 | private $strippedHtml; |
||
77 | |||
78 | /** |
||
79 | * @var array |
||
80 | */ |
||
81 | private $attachments; |
||
82 | |||
83 | /** |
||
84 | * @var string |
||
85 | */ |
||
86 | private $messageUrl; |
||
87 | |||
88 | /** |
||
89 | * @var string |
||
90 | */ |
||
91 | private $contentIdMap; |
||
92 | |||
93 | /** |
||
94 | * @var array |
||
95 | */ |
||
96 | private $messageHeaders; |
||
97 | |||
98 | /** |
||
99 | * Do not let this object be creted without the ::create. |
||
100 | */ |
||
101 | private function __construct() |
||
104 | |||
105 | /** |
||
106 | * @param array $data |
||
107 | * |
||
108 | * @return SendResponse |
||
109 | */ |
||
110 | public static function create(array $data) |
||
162 | |||
163 | /** |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getRecipient() |
||
170 | |||
171 | /** |
||
172 | * @param string $recipient |
||
173 | */ |
||
174 | private function setRecipient($recipient) |
||
178 | |||
179 | /** |
||
180 | * @return string |
||
181 | */ |
||
182 | public function getBodyMime() |
||
186 | |||
187 | /** |
||
188 | * @param string $bodyMime |
||
189 | */ |
||
190 | private function setBodyMime($bodyMime) |
||
194 | |||
195 | /** |
||
196 | * @return string |
||
197 | */ |
||
198 | public function getRecipients() |
||
202 | |||
203 | /** |
||
204 | * @param string $recipients |
||
205 | */ |
||
206 | private function setRecipients($recipients) |
||
210 | |||
211 | /** |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getSender() |
||
218 | |||
219 | /** |
||
220 | * @param string $sender |
||
221 | */ |
||
222 | private function setSender($sender) |
||
226 | |||
227 | /** |
||
228 | * @return string |
||
229 | */ |
||
230 | public function getFrom() |
||
234 | |||
235 | /** |
||
236 | * @param string $from |
||
237 | */ |
||
238 | private function setFrom($from) |
||
242 | |||
243 | /** |
||
244 | * @return string |
||
245 | */ |
||
246 | public function getSubject() |
||
250 | |||
251 | /** |
||
252 | * @param string $subject |
||
253 | */ |
||
254 | private function setSubject($subject) |
||
258 | |||
259 | /** |
||
260 | * @return string |
||
261 | */ |
||
262 | public function getBodyPlain() |
||
266 | |||
267 | /** |
||
268 | * @param string $bodyPlain |
||
269 | */ |
||
270 | private function setBodyPlain($bodyPlain) |
||
274 | |||
275 | /** |
||
276 | * @return string |
||
277 | */ |
||
278 | public function getStrippedText() |
||
282 | |||
283 | /** |
||
284 | * @param string $strippedText |
||
285 | */ |
||
286 | private function setStrippedText($strippedText) |
||
290 | |||
291 | /** |
||
292 | * @return string |
||
293 | */ |
||
294 | public function getStrippedSignature() |
||
298 | |||
299 | /** |
||
300 | * @param string $strippedSignature |
||
301 | */ |
||
302 | private function setStrippedSignature($strippedSignature) |
||
306 | |||
307 | /** |
||
308 | * @return string |
||
309 | */ |
||
310 | public function getBodyHtml() |
||
314 | |||
315 | /** |
||
316 | * @param string $bodyHtml |
||
317 | */ |
||
318 | private function setBodyHtml($bodyHtml) |
||
322 | |||
323 | /** |
||
324 | * @return string |
||
325 | */ |
||
326 | public function getStrippedHtml() |
||
330 | |||
331 | /** |
||
332 | * @param string $strippedHtml |
||
333 | */ |
||
334 | private function setStrippedHtml($strippedHtml) |
||
338 | |||
339 | /** |
||
340 | * @return array |
||
341 | */ |
||
342 | public function getAttachments() |
||
346 | |||
347 | /** |
||
348 | * @param array $attachments |
||
349 | */ |
||
350 | private function setAttachments($attachments) |
||
354 | |||
355 | /** |
||
356 | * @return string |
||
357 | */ |
||
358 | public function getMessageUrl() |
||
362 | |||
363 | /** |
||
364 | * @param string $messageUrl |
||
365 | */ |
||
366 | private function setMessageUrl($messageUrl) |
||
370 | |||
371 | /** |
||
372 | * @return string |
||
373 | */ |
||
374 | public function getContentIdMap() |
||
378 | |||
379 | /** |
||
380 | * @param string $contentIdMap |
||
381 | */ |
||
382 | public function setContentIdMap($contentIdMap) |
||
386 | |||
387 | /** |
||
388 | * @return array |
||
389 | */ |
||
390 | public function getMessageHeaders() |
||
394 | |||
395 | /** |
||
396 | * @param array $messageHeaders |
||
397 | */ |
||
398 | private function setMessageHeaders(array $messageHeaders) |
||
402 | } |
||
403 |