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 |
||
| 24 | class Swift_Transport_MailTransport implements Swift_Transport |
||
|
|
|||
| 25 | { |
||
| 26 | /** Additional parameters to pass to mail() */ |
||
| 27 | private $_extraParams = '-f%s'; |
||
| 28 | |||
| 29 | /** The event dispatcher from the plugin API */ |
||
| 30 | private $_eventDispatcher; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Create a new MailTransport with the $log. |
||
| 34 | * |
||
| 35 | * @param Swift_Events_EventDispatcher $eventDispatcher |
||
| 36 | */ |
||
| 37 | 16 | public function __construct(Swift_Events_EventDispatcher $eventDispatcher) |
|
| 41 | |||
| 42 | /** |
||
| 43 | * Not used. |
||
| 44 | */ |
||
| 45 | public function isStarted() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Not used. |
||
| 52 | */ |
||
| 53 | public function start() |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Not used. |
||
| 59 | */ |
||
| 60 | public function stop() |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Set the additional parameters used on the mail() function. |
||
| 66 | * |
||
| 67 | * This string is formatted for sprintf() where %s is the sender address. |
||
| 68 | * |
||
| 69 | * @param string $params |
||
| 70 | * |
||
| 71 | * @return Swift_Transport_MailTransport |
||
| 72 | */ |
||
| 73 | 2 | public function setExtraParams($params) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * Get the additional parameters used on the mail() function. |
||
| 82 | * |
||
| 83 | * This string is formatted for sprintf() where %s is the sender address. |
||
| 84 | * |
||
| 85 | * @return string |
||
| 86 | */ |
||
| 87 | public function getExtraParams() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Send the given Message. |
||
| 94 | * |
||
| 95 | * Recipient/sender data will be retrieved from the Message API. |
||
| 96 | * The return value is the number of recipients who were accepted for delivery. |
||
| 97 | * |
||
| 98 | * @param Swift_Mime_Message $message |
||
| 99 | * @param string[] $failedRecipients An array of failures (by-reference) |
||
| 100 | * |
||
| 101 | * @return int |
||
| 102 | * |
||
| 103 | * @throws Swift_TransportException |
||
| 104 | */ |
||
| 105 | 15 | public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
|
| 202 | |||
| 203 | /** |
||
| 204 | * Register a plugin. |
||
| 205 | * |
||
| 206 | * @param Swift_Events_EventListener $plugin |
||
| 207 | */ |
||
| 208 | public function registerPlugin(Swift_Events_EventListener $plugin) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Throw a TransportException, first sending it to any listeners |
||
| 215 | * |
||
| 216 | * @param Swift_TransportException $e |
||
| 217 | * |
||
| 218 | * @throws Swift_TransportException |
||
| 219 | */ |
||
| 220 | View Code Duplication | protected function _throwException(Swift_TransportException $e) |
|
| 234 | |||
| 235 | /** |
||
| 236 | * Send mail via the mail() function. |
||
| 237 | * |
||
| 238 | * This method takes the same arguments as PHP mail(). |
||
| 239 | * |
||
| 240 | * @param string $to |
||
| 241 | * @param string $subject |
||
| 242 | * @param string $body |
||
| 243 | * @param string $headers |
||
| 244 | * @param string $extraParams |
||
| 245 | * |
||
| 246 | * @return bool |
||
| 247 | */ |
||
| 248 | public function mail($to, $subject, $body, $headers = null, $extraParams = null) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Determine the best-use reverse path for this message |
||
| 260 | * |
||
| 261 | * @param Swift_Mime_Message $message |
||
| 262 | * |
||
| 263 | * @return mixed|null|string |
||
| 264 | */ |
||
| 265 | 15 | View Code Duplication | private function _getReversePath(Swift_Mime_Message $message) |
| 283 | |||
| 284 | /** |
||
| 285 | * Return php mail extra params to use for invoker->mail. |
||
| 286 | * |
||
| 287 | * @param $extraParams |
||
| 288 | * @param $reversePath |
||
| 289 | * |
||
| 290 | * @return mixed string|null |
||
| 291 | */ |
||
| 292 | 15 | private function _formatExtraParams($extraParams, $reversePath) |
|
| 302 | } |
||
| 303 |
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.