Complex classes like Message 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 Message, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 37 | class Message extends BaseMessage |
||
| 38 | { |
||
| 39 | /** |
||
| 40 | * @var string|array from |
||
| 41 | */ |
||
| 42 | protected $from; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string|array from |
||
| 46 | */ |
||
| 47 | protected $sender; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var array |
||
| 51 | */ |
||
| 52 | protected $to = []; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string|array reply to |
||
| 56 | */ |
||
| 57 | protected $replyTo; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | protected $cc = []; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected $bcc = []; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var string |
||
| 71 | */ |
||
| 72 | protected $subject; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var string |
||
| 76 | */ |
||
| 77 | protected $textBody; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $htmlBody; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var array |
||
| 86 | */ |
||
| 87 | protected $attachments = []; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @var string |
||
| 91 | */ |
||
| 92 | protected $tag; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @var string |
||
| 96 | */ |
||
| 97 | protected $trackOpens = 'account_default'; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var string |
||
| 101 | */ |
||
| 102 | protected $trackClicks = 'account_default'; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @var array |
||
| 106 | */ |
||
| 107 | protected $headers = []; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @var integer |
||
| 111 | */ |
||
| 112 | protected $templateId; |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @var bool |
||
| 116 | */ |
||
| 117 | protected $templateLanguage; |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @var array model associated with the template |
||
| 121 | */ |
||
| 122 | protected $templateModel = []; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @var bool |
||
| 126 | */ |
||
| 127 | protected $inlineCss = true; |
||
| 128 | |||
| 129 | protected $charset = 'utf-8'; |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @inheritdoc |
||
| 133 | */ |
||
| 134 | public function getCharset() |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @inheritdoc |
||
| 141 | */ |
||
| 142 | public function setCharset($charset) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @inheritdoc |
||
| 149 | */ |
||
| 150 | public function getFrom() |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @inheritdoc |
||
| 157 | */ |
||
| 158 | public function setFrom($from) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @return array|string |
||
| 166 | * @since XXX |
||
| 167 | */ |
||
| 168 | public function getSender() |
||
| 172 | |||
| 173 | /** |
||
| 174 | * @param string|array $sender |
||
| 175 | * @return $this |
||
| 176 | * @since XXX |
||
| 177 | */ |
||
| 178 | public function setSender($sender) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * @inheritdoc |
||
| 186 | */ |
||
| 187 | public function getTo() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * @inheritdoc |
||
| 194 | */ |
||
| 195 | public function setTo($to) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @inheritdoc |
||
| 206 | */ |
||
| 207 | public function getReplyTo() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @inheritdoc |
||
| 214 | */ |
||
| 215 | public function setReplyTo($replyTo) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @inheritdoc |
||
| 223 | */ |
||
| 224 | public function getCc() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @inheritdoc |
||
| 231 | */ |
||
| 232 | public function setCc($cc) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @inheritdoc |
||
| 243 | */ |
||
| 244 | public function getBcc() |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @inheritdoc |
||
| 251 | */ |
||
| 252 | public function setBcc($bcc) |
||
| 260 | |||
| 261 | /** |
||
| 262 | * @inheritdoc |
||
| 263 | */ |
||
| 264 | public function getSubject() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @inheritdoc |
||
| 271 | */ |
||
| 272 | public function setSubject($subject) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return string|null text body of the message |
||
| 280 | * @since XXX |
||
| 281 | */ |
||
| 282 | public function getTextBody() |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @inheritdoc |
||
| 289 | */ |
||
| 290 | public function setTextBody($text) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @return string|null html body of the message |
||
| 298 | * @since XXX |
||
| 299 | */ |
||
| 300 | public function getHtmlBody() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @inheritdoc |
||
| 307 | */ |
||
| 308 | public function setHtmlBody($html) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * @return string tag associated to the email |
||
| 316 | * @since XXX |
||
| 317 | */ |
||
| 318 | public function getTag() |
||
| 322 | |||
| 323 | /** |
||
| 324 | * @param string $tag tag which should be associated to the email |
||
| 325 | * @return $this |
||
| 326 | * @since XXX |
||
| 327 | */ |
||
| 328 | public function setTag($tag) |
||
| 333 | |||
| 334 | /** |
||
| 335 | * @param string $trackOpens can be account_default, disabled, enabled |
||
| 336 | * @return $this |
||
| 337 | * @since XXX |
||
| 338 | */ |
||
| 339 | public function setTrackOpens($trackOpens) |
||
| 344 | |||
| 345 | /** |
||
| 346 | * @return string tracking status |
||
| 347 | * @since XXX |
||
| 348 | */ |
||
| 349 | public function getTrackOpens() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @param string $trackClicks can be account_default, disabled, enabled |
||
| 356 | * @return $this |
||
| 357 | * @since XXX |
||
| 358 | */ |
||
| 359 | public function setTrackClicks($trackClicks) |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @return string tracking status |
||
| 367 | * @since XXX |
||
| 368 | */ |
||
| 369 | public function getTrackClicks() |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @param integer $templateId template Id used. in this case, Subject / HtmlBody / TextBody are discarded |
||
| 376 | * @return $this |
||
| 377 | * @since XXX |
||
| 378 | */ |
||
| 379 | public function setTemplateId($templateId) |
||
| 384 | |||
| 385 | /** |
||
| 386 | * @return integer|null current templateId |
||
| 387 | * @since XXX |
||
| 388 | */ |
||
| 389 | public function getTemplateId() |
||
| 393 | |||
| 394 | /** |
||
| 395 | * @param integer $templateId template Id used. in this case, Subject / HtmlBody / TextBody are discarded |
||
|
|
|||
| 396 | * @return $this |
||
| 397 | * @since XXX |
||
| 398 | */ |
||
| 399 | public function setTemplateLanguage($processLanguage) |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return integer|null current templateId |
||
| 407 | * @since XXX |
||
| 408 | */ |
||
| 409 | public function getTemplateLanguage() |
||
| 413 | /** |
||
| 414 | * @param array $templateModel model associated with the template |
||
| 415 | * @return $this |
||
| 416 | * @since XXX |
||
| 417 | */ |
||
| 418 | public function setTemplateModel($templateModel) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @return array current template model |
||
| 429 | * @since XXX |
||
| 430 | */ |
||
| 431 | public function getTemplateModel() |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @param bool $inlineCss define if css should be inlined |
||
| 438 | * @return $this |
||
| 439 | * @since XXX |
||
| 440 | */ |
||
| 441 | public function setInlineCss($inlineCss) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @return bool define if css should be inlined |
||
| 449 | * @since XXX |
||
| 450 | */ |
||
| 451 | public function getInlineCss() |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @param string $headerName |
||
| 458 | * @param string $headerValue |
||
| 459 | * @since XXX |
||
| 460 | */ |
||
| 461 | public function addHeader($headerName, $headerValue) |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @return array|null headers which should be added to the mail |
||
| 468 | * @since XXX |
||
| 469 | */ |
||
| 470 | public function getHeaders() |
||
| 474 | |||
| 475 | /** |
||
| 476 | * @return array|null list of attachments |
||
| 477 | * @since XXX |
||
| 478 | */ |
||
| 479 | public function getAttachments() |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @inheritdoc |
||
| 501 | */ |
||
| 502 | public function attach($fileName, array $options = []) |
||
| 520 | |||
| 521 | /** |
||
| 522 | * @inheritdoc |
||
| 523 | */ |
||
| 524 | public function attachContent($content, array $options = []) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * @inheritdoc |
||
| 545 | */ |
||
| 546 | public function embed($fileName, array $options = []) |
||
| 565 | |||
| 566 | /** |
||
| 567 | * @inheritdoc |
||
| 568 | */ |
||
| 569 | public function embedContent($content, array $options = []) |
||
| 588 | |||
| 589 | /** |
||
| 590 | * Builds an array that represents the message as the MailJet API expects it |
||
| 591 | * @return array message as array that the MailJet API expects |
||
| 592 | */ |
||
| 593 | public function getMailJetMessage() |
||
| 666 | |||
| 667 | /** |
||
| 668 | * @inheritdoc |
||
| 669 | * @todo make real serialization to make message compliant with MailjetAPI |
||
| 670 | */ |
||
| 671 | public function toString() |
||
| 675 | |||
| 676 | |||
| 677 | /** |
||
| 678 | * @param array|string $emailsData email can be defined as string. In this case no transformation is done |
||
| 679 | * or as an array ['[email protected]', '[email protected]' => 'Email 2'] |
||
| 680 | * @return string|null |
||
| 681 | * @since XXX |
||
| 682 | */ |
||
| 683 | public static function stringifyEmails($emailsData) |
||
| 705 | |||
| 706 | public static function convertEmails($emailsData) |
||
| 743 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.