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 |
||
| 10 | class ShowResponse implements ApiResponse |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Only available with message/rfc2822. |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $recipient; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Only available with message/rfc2822. |
||
| 21 | * |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $bodyMime; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $recipients; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var string |
||
| 33 | */ |
||
| 34 | private $sender; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | private $from; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $subject; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | private $bodyPlain; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var string |
||
| 53 | */ |
||
| 54 | private $strippedText; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $strippedSignature; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | private $bodyHtml; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $strippedHtml; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var array |
||
| 73 | */ |
||
| 74 | private $attachments; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var string |
||
| 78 | */ |
||
| 79 | private $messageUrl; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var string |
||
| 83 | */ |
||
| 84 | private $contentIdMap; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @var array |
||
| 88 | */ |
||
| 89 | private $messageHeaders; |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Do not let this object be creted without the ::create. |
||
| 93 | */ |
||
| 94 | private function __construct() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param array $data |
||
| 100 | * |
||
| 101 | * @return SendResponse |
||
| 102 | */ |
||
| 103 | public static function create(array $data) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return string |
||
| 152 | */ |
||
| 153 | public function getRecipient() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param string $recipient |
||
| 160 | */ |
||
| 161 | private function setRecipient($recipient) |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | public function getBodyMime() |
||
| 173 | |||
| 174 | /** |
||
| 175 | * @param string $bodyMime |
||
| 176 | */ |
||
| 177 | private function setBodyMime($bodyMime) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @return string |
||
| 184 | */ |
||
| 185 | public function getRecipients() |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @param string $recipients |
||
| 192 | */ |
||
| 193 | private function setRecipients($recipients) |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @return string |
||
| 200 | */ |
||
| 201 | public function getSender() |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param string $sender |
||
| 208 | */ |
||
| 209 | private function setSender($sender) |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @return string |
||
| 216 | */ |
||
| 217 | public function getFrom() |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @param string $from |
||
| 224 | */ |
||
| 225 | private function setFrom($from) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @return string |
||
| 232 | */ |
||
| 233 | public function getSubject() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @param string $subject |
||
| 240 | */ |
||
| 241 | private function setSubject($subject) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @return string |
||
| 248 | */ |
||
| 249 | public function getBodyPlain() |
||
| 253 | |||
| 254 | /** |
||
| 255 | * @param string $bodyPlain |
||
| 256 | */ |
||
| 257 | private function setBodyPlain($bodyPlain) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @return string |
||
| 264 | */ |
||
| 265 | public function getStrippedText() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @param string $strippedText |
||
| 272 | */ |
||
| 273 | private function setStrippedText($strippedText) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return string |
||
| 280 | */ |
||
| 281 | public function getStrippedSignature() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param string $strippedSignature |
||
| 288 | */ |
||
| 289 | private function setStrippedSignature($strippedSignature) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * @return string |
||
| 296 | */ |
||
| 297 | public function getBodyHtml() |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @param string $bodyHtml |
||
| 304 | */ |
||
| 305 | private function setBodyHtml($bodyHtml) |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @return string |
||
| 312 | */ |
||
| 313 | public function getStrippedHtml() |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param string $strippedHtml |
||
| 320 | */ |
||
| 321 | private function setStrippedHtml($strippedHtml) |
||
| 325 | |||
| 326 | /** |
||
| 327 | * @return array |
||
| 328 | */ |
||
| 329 | public function getAttachments() |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @param array $attachments |
||
| 336 | */ |
||
| 337 | private function setAttachments(array $attachments) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * @return string |
||
| 344 | */ |
||
| 345 | public function getMessageUrl() |
||
| 349 | |||
| 350 | /** |
||
| 351 | * @param string $messageUrl |
||
| 352 | */ |
||
| 353 | private function setMessageUrl($messageUrl) |
||
| 357 | |||
| 358 | /** |
||
| 359 | * @return string |
||
| 360 | */ |
||
| 361 | public function getContentIdMap() |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @param string $contentIdMap |
||
| 368 | */ |
||
| 369 | private function setContentIdMap($contentIdMap) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @return array |
||
| 376 | */ |
||
| 377 | public function getMessageHeaders() |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @param array $messageHeaders |
||
| 384 | */ |
||
| 385 | private function setMessageHeaders(array $messageHeaders) |
||
| 389 | } |
||
| 390 |