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 | // needed as __construct is called from elsewhere explicitly |
||
40 | 23 | public function __construct() |
|
43 | |||
44 | /** |
||
45 | * Set $transports to delegate to. |
||
46 | * |
||
47 | * @param Swift_Transport[] $transports |
||
48 | */ |
||
49 | 22 | public function setTransports(array $transports) |
|
54 | |||
55 | /** |
||
56 | * Get $transports to delegate to. |
||
57 | * |
||
58 | * @return Swift_Transport[] |
||
59 | */ |
||
60 | public function getTransports() |
||
64 | |||
65 | /** |
||
66 | * Get the Transport used in the last successful send operation. |
||
67 | * |
||
68 | * @return Swift_Transport |
||
69 | */ |
||
70 | public function getLastUsedTransport() |
||
74 | |||
75 | /** |
||
76 | * Test if this Transport mechanism has started. |
||
77 | * |
||
78 | * @return bool |
||
79 | */ |
||
80 | 4 | public function isStarted() |
|
84 | |||
85 | /** |
||
86 | * Start this Transport mechanism. |
||
87 | */ |
||
88 | 20 | public function start() |
|
92 | |||
93 | /** |
||
94 | * Stop this Transport mechanism. |
||
95 | */ |
||
96 | 2 | public function stop() |
|
102 | |||
103 | /** |
||
104 | * Check if this Transport mechanism is alive. |
||
105 | * |
||
106 | * If a Transport mechanism session is no longer functional, the method |
||
107 | * returns FALSE. It is the responsibility of the developer to handle this |
||
108 | * case and restart the Transport mechanism manually. |
||
109 | * |
||
110 | * @example |
||
111 | * |
||
112 | * if (!$transport->ping()) { |
||
113 | * $transport->stop(); |
||
114 | * $transport->start(); |
||
115 | * } |
||
116 | * |
||
117 | * The Transport mechanism will be started, if it is not already. |
||
118 | * |
||
119 | * It is undefined if the Transport mechanism attempts to restart as long as |
||
120 | * the return value reflects whether the mechanism is now functional. |
||
121 | * |
||
122 | * @return bool TRUE if the transport is alive |
||
123 | */ |
||
124 | public function ping() |
||
134 | |||
135 | /** |
||
136 | * Send the given Message. |
||
137 | * |
||
138 | * Recipient/sender data will be retrieved from the Message API. |
||
139 | * The return value is the number of recipients who were accepted for delivery. |
||
140 | * |
||
141 | * @param Swift_Mime_Message $message |
||
142 | * @param string[] $failedRecipients An array of failures by-reference |
||
143 | * |
||
144 | * @return int |
||
145 | * |
||
146 | * @throws Swift_TransportException |
||
147 | */ |
||
148 | 10 | View Code Duplication | public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
180 | |||
181 | /** |
||
182 | * Register a plugin. |
||
183 | * |
||
184 | * @param Swift_Events_EventListener $plugin |
||
185 | */ |
||
186 | 2 | public function registerPlugin(Swift_Events_EventListener $plugin) |
|
192 | |||
193 | /** |
||
194 | * Rotates the transport list around and returns the first instance. |
||
195 | * |
||
196 | * @return Swift_Transport |
||
197 | */ |
||
198 | 18 | protected function _getNextTransport() |
|
207 | |||
208 | /** |
||
209 | * Tag the currently used (top of stack) transport as dead/useless. |
||
210 | */ |
||
211 | 10 | protected function _killCurrentTransport() |
|
224 | } |
||
225 |
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.