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 array | ||
| 91 | */ | ||
| 92 | protected $inlinedAttachments = []; | ||
| 93 | |||
| 94 | /** | ||
| 95 | * @var string | ||
| 96 | */ | ||
| 97 | protected $tag; | ||
| 98 | |||
| 99 | /** | ||
| 100 | * @var string | ||
| 101 | */ | ||
| 102 | protected $trackOpens = 'account_default'; | ||
| 103 | |||
| 104 | /** | ||
| 105 | * @var string | ||
| 106 | */ | ||
| 107 | protected $trackClicks = 'account_default'; | ||
| 108 | |||
| 109 | /** | ||
| 110 | * @var array | ||
| 111 | */ | ||
| 112 | protected $headers = []; | ||
| 113 | |||
| 114 | /** | ||
| 115 | * @var integer | ||
| 116 | */ | ||
| 117 | protected $templateId; | ||
| 118 | |||
| 119 | /** | ||
| 120 | * @var bool | ||
| 121 | */ | ||
| 122 | protected $templateLanguage; | ||
| 123 | |||
| 124 | /** | ||
| 125 | * @var array model associated with the template | ||
| 126 | */ | ||
| 127 | protected $templateModel = []; | ||
| 128 | |||
| 129 | /** | ||
| 130 | * @var bool | ||
| 131 | */ | ||
| 132 | protected $inlineCss = true; | ||
| 133 | |||
| 134 | protected $charset = 'utf-8'; | ||
| 135 | |||
| 136 | /** | ||
| 137 | * @inheritdoc | ||
| 138 | */ | ||
| 139 | public function getCharset() | ||
| 143 | |||
| 144 | /** | ||
| 145 | * @inheritdoc | ||
| 146 | */ | ||
| 147 | public function setCharset($charset) | ||
| 151 | |||
| 152 | /** | ||
| 153 | * @inheritdoc | ||
| 154 | */ | ||
| 155 | public function getFrom() | ||
| 159 | |||
| 160 | /** | ||
| 161 | * @inheritdoc | ||
| 162 | */ | ||
| 163 | public function setFrom($from) | ||
| 168 | |||
| 169 | /** | ||
| 170 | * @return array|string | ||
| 171 | * @since XXX | ||
| 172 | */ | ||
| 173 | public function getSender() | ||
| 177 | |||
| 178 | /** | ||
| 179 | * @param string|array $sender | ||
| 180 | * @return $this | ||
| 181 | * @since XXX | ||
| 182 | */ | ||
| 183 | public function setSender($sender) | ||
| 188 | |||
| 189 | /** | ||
| 190 | * @inheritdoc | ||
| 191 | */ | ||
| 192 | public function getTo() | ||
| 196 | |||
| 197 | /** | ||
| 198 | * @inheritdoc | ||
| 199 | */ | ||
| 200 | public function setTo($to) | ||
| 208 | |||
| 209 | /** | ||
| 210 | * @inheritdoc | ||
| 211 | */ | ||
| 212 | public function getReplyTo() | ||
| 216 | |||
| 217 | /** | ||
| 218 | * @inheritdoc | ||
| 219 | */ | ||
| 220 | public function setReplyTo($replyTo) | ||
| 225 | |||
| 226 | /** | ||
| 227 | * @inheritdoc | ||
| 228 | */ | ||
| 229 | public function getCc() | ||
| 233 | |||
| 234 | /** | ||
| 235 | * @inheritdoc | ||
| 236 | */ | ||
| 237 | public function setCc($cc) | ||
| 245 | |||
| 246 | /** | ||
| 247 | * @inheritdoc | ||
| 248 | */ | ||
| 249 | public function getBcc() | ||
| 253 | |||
| 254 | /** | ||
| 255 | * @inheritdoc | ||
| 256 | */ | ||
| 257 | public function setBcc($bcc) | ||
| 265 | |||
| 266 | /** | ||
| 267 | * @inheritdoc | ||
| 268 | */ | ||
| 269 | public function getSubject() | ||
| 273 | |||
| 274 | /** | ||
| 275 | * @inheritdoc | ||
| 276 | */ | ||
| 277 | public function setSubject($subject) | ||
| 282 | |||
| 283 | /** | ||
| 284 | * @return string|null text body of the message | ||
| 285 | * @since XXX | ||
| 286 | */ | ||
| 287 | public function getTextBody() | ||
| 291 | |||
| 292 | /** | ||
| 293 | * @inheritdoc | ||
| 294 | */ | ||
| 295 | public function setTextBody($text) | ||
| 300 | |||
| 301 | /** | ||
| 302 | * @return string|null html body of the message | ||
| 303 | * @since XXX | ||
| 304 | */ | ||
| 305 | public function getHtmlBody() | ||
| 309 | |||
| 310 | /** | ||
| 311 | * @inheritdoc | ||
| 312 | */ | ||
| 313 | public function setHtmlBody($html) | ||
| 318 | |||
| 319 | /** | ||
| 320 | * @return string tag associated to the email | ||
| 321 | * @since XXX | ||
| 322 | */ | ||
| 323 | public function getTag() | ||
| 327 | |||
| 328 | /** | ||
| 329 | * @param string $tag tag which should be associated to the email | ||
| 330 | * @return $this | ||
| 331 | * @since XXX | ||
| 332 | */ | ||
| 333 | public function setTag($tag) | ||
| 338 | |||
| 339 | /** | ||
| 340 | * @param string $trackOpens can be account_default, disabled, enabled | ||
| 341 | * @return $this | ||
| 342 | * @since XXX | ||
| 343 | */ | ||
| 344 | public function setTrackOpens($trackOpens) | ||
| 349 | |||
| 350 | /** | ||
| 351 | * @return string tracking status | ||
| 352 | * @since XXX | ||
| 353 | */ | ||
| 354 | public function getTrackOpens() | ||
| 358 | |||
| 359 | /** | ||
| 360 | * @param string $trackClicks can be account_default, disabled, enabled | ||
| 361 | * @return $this | ||
| 362 | * @since XXX | ||
| 363 | */ | ||
| 364 | public function setTrackClicks($trackClicks) | ||
| 369 | |||
| 370 | /** | ||
| 371 | * @return string tracking status | ||
| 372 | * @since XXX | ||
| 373 | */ | ||
| 374 | public function getTrackClicks() | ||
| 378 | |||
| 379 | /** | ||
| 380 | * @param integer $templateId template Id used. in this case, Subject / HtmlBody / TextBody are discarded | ||
| 381 | * @return $this | ||
| 382 | * @since XXX | ||
| 383 | */ | ||
| 384 | public function setTemplateId($templateId) | ||
| 389 | |||
| 390 | /** | ||
| 391 | * @return integer|null current templateId | ||
| 392 | * @since XXX | ||
| 393 | */ | ||
| 394 | public function getTemplateId() | ||
| 398 | |||
| 399 | /** | ||
| 400 | * @param integer $templateId template Id used. in this case, Subject / HtmlBody / TextBody are discarded | ||
|  | |||
| 401 | * @return $this | ||
| 402 | * @since XXX | ||
| 403 | */ | ||
| 404 | public function setTemplateLanguage($processLanguage) | ||
| 409 | |||
| 410 | /** | ||
| 411 | * @return integer|null current templateId | ||
| 412 | * @since XXX | ||
| 413 | */ | ||
| 414 | public function getTemplateLanguage() | ||
| 418 | /** | ||
| 419 | * @param array $templateModel model associated with the template | ||
| 420 | * @return $this | ||
| 421 | * @since XXX | ||
| 422 | */ | ||
| 423 | public function setTemplateModel($templateModel) | ||
| 431 | |||
| 432 | /** | ||
| 433 | * @return array current template model | ||
| 434 | * @since XXX | ||
| 435 | */ | ||
| 436 | public function getTemplateModel() | ||
| 440 | |||
| 441 | /** | ||
| 442 | * @param bool $inlineCss define if css should be inlined | ||
| 443 | * @return $this | ||
| 444 | * @since XXX | ||
| 445 | */ | ||
| 446 | public function setInlineCss($inlineCss) | ||
| 451 | |||
| 452 | /** | ||
| 453 | * @return bool define if css should be inlined | ||
| 454 | * @since XXX | ||
| 455 | */ | ||
| 456 | public function getInlineCss() | ||
| 460 | |||
| 461 | /** | ||
| 462 | * @param string $headerName | ||
| 463 | * @param string $headerValue | ||
| 464 | * @since XXX | ||
| 465 | */ | ||
| 466 | public function addHeader($headerName, $headerValue) | ||
| 470 | |||
| 471 | /** | ||
| 472 | * @return array|null headers which should be added to the mail | ||
| 473 | * @since XXX | ||
| 474 | */ | ||
| 475 | public function getHeaders() | ||
| 479 | |||
| 480 | /** | ||
| 481 | * @return array|null list of attachments | ||
| 482 | * @since XXX | ||
| 483 | */ | ||
| 484 | public function getAttachments() | ||
| 503 | |||
| 504 | /** | ||
| 505 | * @return array|null list of inlinedAttachments | ||
| 506 | * @since XXX | ||
| 507 | */ | ||
| 508 | public function getInlinedAttachments() | ||
| 527 | |||
| 528 | |||
| 529 | /** | ||
| 530 | * @inheritdoc | ||
| 531 | */ | ||
| 532 | public function attach($fileName, array $options = []) | ||
| 550 | |||
| 551 | /** | ||
| 552 | * @inheritdoc | ||
| 553 | */ | ||
| 554 | public function attachContent($content, array $options = []) | ||
| 572 | |||
| 573 | /** | ||
| 574 | * @inheritdoc | ||
| 575 | */ | ||
| 576 | public function embed($fileName, array $options = []) | ||
| 595 | |||
| 596 | /** | ||
| 597 | * @inheritdoc | ||
| 598 | */ | ||
| 599 | public function embedContent($content, array $options = []) | ||
| 618 | |||
| 619 | /** | ||
| 620 | * @inheritdoc | ||
| 621 | * @todo make real serialization to make message compliant with MailjetAPI | ||
| 622 | */ | ||
| 623 | public function toString() | ||
| 627 | |||
| 628 | |||
| 629 | /** | ||
| 630 | * @param array|string $emailsData email can be defined as string. In this case no transformation is done | ||
| 631 | * or as an array ['[email protected]', '[email protected]' => 'Email 2'] | ||
| 632 | * @return string|null | ||
| 633 | * @since XXX | ||
| 634 | */ | ||
| 635 | public static function stringifyEmails($emailsData) | ||
| 694 | } | 
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.