Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 16 | class Swift_Message extends Swift_Mime_SimpleMessage |
||
|
|
|||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var Swift_Signers_HeaderSigner[] |
||
| 20 | */ |
||
| 21 | private $headerSigners = array(); |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var Swift_Signers_BodySigner[] |
||
| 25 | */ |
||
| 26 | private $bodySigners = array(); |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var array |
||
| 30 | */ |
||
| 31 | private $savedMessage = array(); |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Create a new Message. |
||
| 35 | * |
||
| 36 | * Details may be optionally passed into the constructor. |
||
| 37 | * |
||
| 38 | * @param string $subject |
||
| 39 | * @param string $body |
||
| 40 | * @param string $contentType |
||
| 41 | * @param string $charset |
||
| 42 | */ |
||
| 43 | 109 | public function __construct($subject = null, $body = null, $contentType = null, $charset = null) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Create a new Message. |
||
| 64 | * |
||
| 65 | * @param string $subject |
||
| 66 | * @param string $body |
||
| 67 | * @param string $contentType |
||
| 68 | * @param string $charset |
||
| 69 | * |
||
| 70 | * @return Swift_Message |
||
| 71 | */ |
||
| 72 | 59 | public static function newInstance($subject = null, $body = null, $contentType = null, $charset = null) |
|
| 76 | |||
| 77 | /** |
||
| 78 | * Add a MimePart to this Message. |
||
| 79 | * |
||
| 80 | * @param string|Swift_OutputByteStream $body |
||
| 81 | * @param string $contentType |
||
| 82 | * @param string $charset |
||
| 83 | * |
||
| 84 | * @return Swift_Mime_SimpleMessage |
||
| 85 | */ |
||
| 86 | 3 | public function addPart($body, $contentType = null, $charset = null) |
|
| 96 | |||
| 97 | /** |
||
| 98 | * Attach a new signature handler to the message. |
||
| 99 | * |
||
| 100 | * @param Swift_Signer $signer |
||
| 101 | * |
||
| 102 | * @return Swift_Message |
||
| 103 | */ |
||
| 104 | 9 | public function attachSigner(Swift_Signer $signer) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Attach a new signature handler to the message. |
||
| 117 | * |
||
| 118 | * @param Swift_Signer $signer |
||
| 119 | * |
||
| 120 | * @return Swift_Message |
||
| 121 | */ |
||
| 122 | public function detachSigner(Swift_Signer $signer) |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Get this message as a complete string. |
||
| 147 | * |
||
| 148 | * @return string |
||
| 149 | */ |
||
| 150 | 82 | View Code Duplication | public function toString() |
| 166 | |||
| 167 | /** |
||
| 168 | * Write this message to a {@link Swift_InputByteStream}. |
||
| 169 | * |
||
| 170 | * @param Swift_InputByteStream $is |
||
| 171 | */ |
||
| 172 | 17 | View Code Duplication | public function toByteStream(Swift_InputByteStream $is) |
| 188 | |||
| 189 | public function __wakeup() |
||
| 193 | |||
| 194 | /** |
||
| 195 | * loops through signers and apply the signatures. |
||
| 196 | */ |
||
| 197 | 8 | protected function doSign() |
|
| 219 | |||
| 220 | /** |
||
| 221 | * save the message before any signature is applied. |
||
| 222 | */ |
||
| 223 | 8 | protected function saveMessage() |
|
| 238 | |||
| 239 | /** |
||
| 240 | * save the original headers. |
||
| 241 | * |
||
| 242 | * @param array $altered |
||
| 243 | */ |
||
| 244 | 8 | protected function saveHeaders(array $altered) |
|
| 254 | |||
| 255 | /** |
||
| 256 | * Remove or restore altered headers. |
||
| 257 | */ |
||
| 258 | 8 | protected function restoreHeaders() |
|
| 270 | |||
| 271 | /** |
||
| 272 | * Restore message body. |
||
| 273 | */ |
||
| 274 | 8 | protected function restoreMessage() |
|
| 282 | |||
| 283 | /** |
||
| 284 | * Clone Message Signers. |
||
| 285 | * |
||
| 286 | * @see Swift_Mime_SimpleMimeEntity::__clone() |
||
| 287 | */ |
||
| 288 | 5 | public function __clone() |
|
| 300 | } |
||
| 301 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.