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 | 20 | 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 | 19 | public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
|
206 | |||
207 | /** |
||
208 | * Register a plugin. |
||
209 | * |
||
210 | * @param Swift_Events_EventListener $plugin |
||
211 | */ |
||
212 | public function registerPlugin(Swift_Events_EventListener $plugin) |
||
216 | |||
217 | /** |
||
218 | * Throw a TransportException, first sending it to any listeners |
||
219 | * |
||
220 | * @param Swift_TransportException $e |
||
221 | * |
||
222 | 1 | * @throws Swift_TransportException |
|
223 | */ |
||
224 | 1 | View Code Duplication | protected function _throwException(Swift_TransportException $e) |
238 | |||
239 | /** |
||
240 | * Send mail via the mail() function. |
||
241 | * |
||
242 | * This method takes the same arguments as PHP mail(). |
||
243 | * |
||
244 | * @param string $to |
||
245 | * @param string $subject |
||
246 | * @param string $body |
||
247 | * @param string $headers |
||
248 | * @param string $extraParams |
||
249 | * |
||
250 | 3 | * @return bool |
|
251 | */ |
||
252 | public function mail($to, $subject, $body, $headers = null, $extraParams = null) |
||
263 | |||
264 | /** |
||
265 | * Determine the best-use reverse path for this message |
||
266 | * |
||
267 | 18 | * @param Swift_Mime_Message $message |
|
268 | * |
||
269 | 18 | * @return mixed|null|string |
|
270 | 18 | */ |
|
271 | 18 | View Code Duplication | private function _getReversePath(Swift_Mime_Message $message) |
289 | |||
290 | /** |
||
291 | * Fix CVE-2016-10074 by disallowing potentially unsafe shell characters. |
||
292 | * |
||
293 | * Note that escapeshellarg and escapeshellcmd are inadequate for our purposes, especially on Windows. |
||
294 | 18 | * |
|
295 | * @param string $string The string to be validated |
||
296 | 18 | * |
|
297 | 17 | * @return bool |
|
298 | 17 | */ |
|
299 | 17 | private function _isShellSafe($string) |
|
323 | |||
324 | /** |
||
325 | * Return php mail extra params to use for invoker->mail. |
||
326 | * |
||
327 | * @param string $extraParams |
||
328 | * @param string $reversePath |
||
329 | * |
||
330 | * @return null|string |
||
331 | */ |
||
332 | private function _formatExtraParams($extraParams, $reversePath) |
||
348 | } |
||
349 |
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.