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) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @return string |
||
| 159 | */ |
||
| 160 | public function getRecipient() |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @param string $recipient |
||
| 167 | */ |
||
| 168 | private function setRecipient($recipient) |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @return string |
||
| 175 | */ |
||
| 176 | public function getBodyMime() |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param string $bodyMime |
||
| 183 | */ |
||
| 184 | private function setBodyMime($bodyMime) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | public function getRecipients() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @param string $recipients |
||
| 199 | */ |
||
| 200 | private function setRecipients($recipients) |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | public function getSender() |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @param string $sender |
||
| 215 | */ |
||
| 216 | private function setSender($sender) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return string |
||
| 223 | */ |
||
| 224 | public function getFrom() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @param string $from |
||
| 231 | */ |
||
| 232 | private function setFrom($from) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | public function getSubject() |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @param string $subject |
||
| 247 | */ |
||
| 248 | private function setSubject($subject) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * @return string |
||
| 255 | */ |
||
| 256 | public function getBodyPlain() |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @param string $bodyPlain |
||
| 263 | */ |
||
| 264 | private function setBodyPlain($bodyPlain) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | public function getStrippedText() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param string $strippedText |
||
| 279 | */ |
||
| 280 | private function setStrippedText($strippedText) |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @return string |
||
| 287 | */ |
||
| 288 | public function getStrippedSignature() |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @param string $strippedSignature |
||
| 295 | */ |
||
| 296 | private function setStrippedSignature($strippedSignature) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @return string |
||
| 303 | */ |
||
| 304 | public function getBodyHtml() |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @param string $bodyHtml |
||
| 311 | */ |
||
| 312 | private function setBodyHtml($bodyHtml) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @return string |
||
| 319 | */ |
||
| 320 | public function getStrippedHtml() |
||
| 324 | |||
| 325 | /** |
||
| 326 | * @param string $strippedHtml |
||
| 327 | */ |
||
| 328 | private function setStrippedHtml($strippedHtml) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @return array |
||
| 335 | */ |
||
| 336 | public function getAttachments() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @return string |
||
| 343 | */ |
||
| 344 | public function getMessageUrl() |
||
| 345 | { |
||
| 346 | return $this->messageUrl; |
||
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @param string $messageUrl |
||
| 351 | */ |
||
| 352 | private function setMessageUrl($messageUrl) |
||
| 353 | { |
||
| 354 | $this->messageUrl = $messageUrl; |
||
| 355 | } |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @return string |
||
| 359 | */ |
||
| 360 | public function getContentIdMap() |
||
| 361 | { |
||
| 362 | return $this->contentIdMap; |
||
| 363 | } |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @return array |
||
| 367 | */ |
||
| 368 | public function getMessageHeaders() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @param array $messageHeaders |
||
| 375 | */ |
||
| 376 | private function setMessageHeaders(array $messageHeaders) |
||
| 380 | } |
||
| 381 |