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_Transport_LoadBalancedTransport implements Swift_Transport |
||
|
|
|||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Transports which are deemed useless. |
||
| 20 | * |
||
| 21 | * @var Swift_Transport[] |
||
| 22 | */ |
||
| 23 | private $_deadTransports = array(); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The Transports which are used in rotation. |
||
| 27 | * |
||
| 28 | * @var Swift_Transport[] |
||
| 29 | */ |
||
| 30 | protected $_transports = array(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The Transport used in the last successful send operation. |
||
| 34 | * |
||
| 35 | * @var Swift_Transport |
||
| 36 | */ |
||
| 37 | protected $_lastUsedTransport; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Constructor. |
||
| 41 | */ |
||
| 42 | public function __construct() |
||
| 45 | |||
| 46 | 22 | /** |
|
| 47 | 22 | * Set $transports to delegate to. |
|
| 48 | 22 | * |
|
| 49 | * @param Swift_Transport[] $transports |
||
| 50 | */ |
||
| 51 | public function setTransports(array $transports) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get $transports to delegate to. |
||
| 59 | * |
||
| 60 | * @return Swift_Transport[] |
||
| 61 | */ |
||
| 62 | public function getTransports() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get the Transport used in the last successful send operation. |
||
| 69 | * |
||
| 70 | * @return Swift_Transport |
||
| 71 | */ |
||
| 72 | public function getLastUsedTransport() |
||
| 76 | |||
| 77 | 4 | /** |
|
| 78 | * Test if this Transport mechanism has started. |
||
| 79 | * |
||
| 80 | * @return bool |
||
| 81 | */ |
||
| 82 | public function isStarted() |
||
| 86 | 20 | ||
| 87 | /** |
||
| 88 | * Start this Transport mechanism. |
||
| 89 | */ |
||
| 90 | public function start() |
||
| 94 | 2 | ||
| 95 | 2 | /** |
|
| 96 | 2 | * Stop this Transport mechanism. |
|
| 97 | */ |
||
| 98 | public function stop() |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Send the given Message. |
||
| 107 | * |
||
| 108 | * Recipient/sender data will be retrieved from the Message API. |
||
| 109 | * The return value is the number of recipients who were accepted for delivery. |
||
| 110 | * |
||
| 111 | 10 | * @param Swift_Mime_Message $message |
|
| 112 | * @param string[] $failedRecipients An array of failures by-reference |
||
| 113 | 10 | * |
|
| 114 | 10 | * @return int |
|
| 115 | 10 | * |
|
| 116 | * @throws Swift_TransportException |
||
| 117 | 10 | */ |
|
| 118 | 10 | View Code Duplication | public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
| 150 | |||
| 151 | 2 | /** |
|
| 152 | 2 | * Register a plugin. |
|
| 153 | 2 | * |
|
| 154 | 2 | * @param Swift_Events_EventListener $plugin |
|
| 155 | */ |
||
| 156 | public function registerPlugin(Swift_Events_EventListener $plugin) |
||
| 162 | |||
| 163 | 18 | /** |
|
| 164 | 18 | * Rotates the transport list around and returns the first instance. |
|
| 165 | 18 | * |
|
| 166 | 18 | * @return Swift_Transport |
|
| 167 | */ |
||
| 168 | 18 | protected function _getNextTransport() |
|
| 177 | 10 | ||
| 178 | /** |
||
| 179 | * Tag the currently used (top of stack) transport as dead/useless. |
||
| 180 | 10 | */ |
|
| 181 | 10 | protected function _killCurrentTransport() |
|
| 194 | } |
||
| 195 |
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.