Complex classes like SwiftTwigMailTemplate 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 SwiftTwigMailTemplate, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class SwiftTwigMailTemplate implements SwiftMailTemplate |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var \Twig_Environment |
||
| 11 | */ |
||
| 12 | protected $twigEnvironment; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $twigPath; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string|array |
||
| 21 | */ |
||
| 22 | protected $fromAddresses; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $fromName = null; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var string|array |
||
| 31 | */ |
||
| 32 | protected $toAddresses; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $toName = null; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string|array |
||
| 41 | */ |
||
| 42 | protected $bccAddresses; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $bccName = null; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string|array |
||
| 51 | */ |
||
| 52 | protected $ccAddresses; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $ccName = null; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string|array |
||
| 61 | */ |
||
| 62 | protected $replyToAddresses; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | protected $replyToName = null; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var int |
||
| 71 | */ |
||
| 72 | protected $maxLineLength = 1000; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @var int |
||
| 76 | */ |
||
| 77 | protected $priority; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @var string |
||
| 81 | */ |
||
| 82 | protected $readReceiptTo; |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @var string |
||
| 86 | */ |
||
| 87 | protected $returnPath; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * SwiftTwigMailGenerator constructor. |
||
| 91 | * |
||
| 92 | * @param \Twig_Environment $twig_Environment |
||
| 93 | * @param string $twigPath |
||
| 94 | */ |
||
| 95 | 4 | public function __construct(\Twig_Environment $twig_Environment, string $twigPath) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * @param array $data |
||
| 103 | * |
||
| 104 | * @return \Swift_Message |
||
| 105 | */ |
||
| 106 | 4 | public function renderMail(array $data = []) :\Swift_Message |
|
| 173 | |||
| 174 | /** |
||
| 175 | * @param array|string $fromAddresses |
||
| 176 | */ |
||
| 177 | 1 | public function setFromAddresses($fromAddresses) |
|
| 181 | |||
| 182 | /** |
||
| 183 | * @param string $fromName |
||
| 184 | */ |
||
| 185 | 1 | public function setFromName($fromName) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * @param array|string $toAddresses |
||
| 192 | */ |
||
| 193 | 1 | public function setToAddresses($toAddresses) |
|
| 197 | |||
| 198 | /** |
||
| 199 | * @param string $toName |
||
| 200 | */ |
||
| 201 | 1 | public function setToName($toName) |
|
| 205 | |||
| 206 | /** |
||
| 207 | * @param array|string $bccAddresses |
||
| 208 | */ |
||
| 209 | 1 | public function setBccAddresses($bccAddresses) |
|
| 213 | |||
| 214 | /** |
||
| 215 | * @param string $bccName |
||
| 216 | */ |
||
| 217 | 1 | public function setBccName($bccName) |
|
| 221 | |||
| 222 | /** |
||
| 223 | * @param array|string $ccAddresses |
||
| 224 | */ |
||
| 225 | 1 | public function setCcAddresses($ccAddresses) |
|
| 229 | |||
| 230 | /** |
||
| 231 | * @param string $ccName |
||
| 232 | */ |
||
| 233 | 1 | public function setCcName($ccName) |
|
| 237 | |||
| 238 | /** |
||
| 239 | * @param array|string $replyToAddresses |
||
| 240 | */ |
||
| 241 | 1 | public function setReplyToAddresses($replyToAddresses) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * @param string $replyToName |
||
| 248 | */ |
||
| 249 | 1 | public function setReplyToName($replyToName) |
|
| 253 | |||
| 254 | /** |
||
| 255 | * @param int $maxLineLength |
||
| 256 | */ |
||
| 257 | 1 | public function setMaxLineLength($maxLineLength) |
|
| 261 | |||
| 262 | /** |
||
| 263 | * @param int $priority |
||
| 264 | */ |
||
| 265 | 1 | public function setPriority($priority) |
|
| 269 | |||
| 270 | /** |
||
| 271 | * @param string $readReceiptTo |
||
| 272 | */ |
||
| 273 | 1 | public function setReadReceiptTo($readReceiptTo) |
|
| 277 | |||
| 278 | /** |
||
| 279 | * @param string $returnPath |
||
| 280 | */ |
||
| 281 | 1 | public function setReturnPath($returnPath) |
|
| 285 | |||
| 286 | /** |
||
| 287 | * Removes the HTML tags from the text. |
||
| 288 | * |
||
| 289 | * @param string $s |
||
| 290 | * @param string $keep The list of tags to keep |
||
| 291 | * @param string $expand The list of tags to remove completely, along their content |
||
| 292 | */ |
||
| 293 | 1 | private function removeHtml(string $s, string $keep = '', string $expand = 'script|style|noframes|select|option') :string |
|
| 335 | |||
| 336 | /** |
||
| 337 | * @param string $s |
||
| 338 | * @param string $openTag |
||
| 339 | * @param string $closeTag |
||
| 340 | * |
||
| 341 | * @return mixed|string |
||
| 342 | */ |
||
| 343 | 1 | private function removeElement(string $s, string $openTag, string $closeTag) |
|
| 357 | |||
| 358 | /** |
||
| 359 | * @param string $s |
||
| 360 | * @param array $tagToKeep |
||
| 361 | * @param string $initial |
||
| 362 | * @param string $finalize |
||
| 363 | * |
||
| 364 | * @return string |
||
| 365 | */ |
||
| 366 | private function keepTag(string $s, array $tagToKeep, string $initial, string $finalize):string |
||
| 376 | } |
||
| 377 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.