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_FailoverTransport extends Swift_Transport_LoadBalancedTransport |
||
|
|||
17 | { |
||
18 | /** |
||
19 | * Registered transport currently used. |
||
20 | * |
||
21 | * @var Swift_Transport |
||
22 | */ |
||
23 | private $_currentTransport; |
||
24 | |||
25 | // needed as __construct is called from elsewhere explicitly |
||
26 | 11 | public function __construct() |
|
30 | |||
31 | /** |
||
32 | * Check if this Transport mechanism is alive. |
||
33 | * |
||
34 | * If a Transport mechanism session is no longer functional, the method |
||
35 | * returns FALSE. It is the responsibility of the developer to handle this |
||
36 | * case and restart the Transport mechanism manually. |
||
37 | * |
||
38 | * @example |
||
39 | * |
||
40 | * if (!$transport->ping()) { |
||
41 | * $transport->stop(); |
||
42 | * $transport->start(); |
||
43 | * } |
||
44 | * |
||
45 | * The Transport mechanism will be started, if it is not already. |
||
46 | * |
||
47 | * It is undefined if the Transport mechanism attempts to restart as long as |
||
48 | * the return value reflects whether the mechanism is now functional. |
||
49 | * |
||
50 | * @return bool TRUE if the transport is alive |
||
51 | */ |
||
52 | public function ping() |
||
66 | |||
67 | /** |
||
68 | * Send the given Message. |
||
69 | * |
||
70 | * Recipient/sender data will be retrieved from the Message API. |
||
71 | * The return value is the number of recipients who were accepted for delivery. |
||
72 | * |
||
73 | * @param Swift_Mime_Message $message |
||
74 | * @param string[] $failedRecipients An array of failures by-reference |
||
75 | * |
||
76 | * @return int |
||
77 | * @throws Swift_TransportException |
||
78 | */ |
||
79 | 8 | View Code Duplication | public function send(Swift_Mime_Message $message, &$failedRecipients = null) |
112 | |||
113 | 8 | protected function _getNextTransport() |
|
121 | |||
122 | 5 | protected function _killCurrentTransport() |
|
127 | } |
||
128 |
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.