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_Mime_SimpleHeaderFactory implements Swift_Mime_HeaderFactory |
||
|
|
|||
| 17 | { |
||
| 18 | /** |
||
| 19 | * The HeaderEncoder used by these headers |
||
| 20 | * |
||
| 21 | * @var Swift_Mime_HeaderEncoder |
||
| 22 | */ |
||
| 23 | private $_encoder; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * The Encoder used by parameters |
||
| 27 | * |
||
| 28 | * @var Swift_Encoder |
||
| 29 | */ |
||
| 30 | private $_paramEncoder; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The Email Validator |
||
| 34 | * |
||
| 35 | * @var Swift_EmailValidatorBridge |
||
| 36 | */ |
||
| 37 | private $_emailValidator; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The charset of created Headers |
||
| 41 | * |
||
| 42 | * @var null|string |
||
| 43 | */ |
||
| 44 | private $_charset; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Creates a new SimpleHeaderFactory using $encoder and $paramEncoder. |
||
| 48 | * |
||
| 49 | * @param Swift_Mime_HeaderEncoder $encoder |
||
| 50 | * @param Swift_Encoder $paramEncoder |
||
| 51 | * @param Swift_EmailValidatorBridge $emailValidator |
||
| 52 | * @param string|null $charset |
||
| 53 | */ |
||
| 54 | 170 | public function __construct(Swift_Mime_HeaderEncoder $encoder, Swift_Encoder $paramEncoder, Swift_EmailValidatorBridge $emailValidator, $charset = null) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Create a new Mailbox Header with a list of $addresses. |
||
| 65 | * |
||
| 66 | * @param string $name |
||
| 67 | * @param array|string|null $addresses |
||
| 68 | * |
||
| 69 | * @return Swift_Mime_Header |
||
| 70 | 114 | */ |
|
| 71 | View Code Duplication | public function createMailboxHeader($name, $addresses = null) |
|
| 83 | |||
| 84 | /** |
||
| 85 | * Create a new Date header using $timestamp (UNIX time). |
||
| 86 | * |
||
| 87 | * @param string $name |
||
| 88 | * @param int|null $timestamp |
||
| 89 | 112 | * |
|
| 90 | * @return Swift_Mime_Header |
||
| 91 | 112 | */ |
|
| 92 | 112 | public function createDateHeader($name, $timestamp = null) |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Create a new basic text header with $name and $value. |
||
| 107 | * |
||
| 108 | 152 | * @param string $name |
|
| 109 | * @param string $value |
||
| 110 | 152 | * |
|
| 111 | 152 | * @return Swift_Mime_Header |
|
| 112 | 150 | */ |
|
| 113 | public function createTextHeader($name, $value = null) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Create a new ParameterizedHeader with $name, $value and $params. |
||
| 128 | 147 | * |
|
| 129 | * @param string $name |
||
| 130 | 147 | * @param string $value |
|
| 131 | 50 | * @param array $params |
|
| 132 | * |
||
| 133 | 147 | * @return Swift_Mime_ParameterizedHeader |
|
| 134 | */ |
||
| 135 | public function createParameterizedHeader($name, $value = null, $params = array()) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Create a new ID header for Message-ID or Content-ID. |
||
| 159 | 124 | * |
|
| 160 | * @param string $name |
||
| 161 | 124 | * @param string|array|null $ids |
|
| 162 | * |
||
| 163 | 124 | * @return Swift_Mime_Header |
|
| 164 | 122 | */ |
|
| 165 | View Code Duplication | public function createIdHeader($name, $ids = null) |
|
| 177 | |||
| 178 | /** |
||
| 179 | * Create a new Path header with an address (path) in it. |
||
| 180 | 33 | * |
|
| 181 | * @param string $name |
||
| 182 | 33 | * @param string $path |
|
| 183 | 33 | * |
|
| 184 | 31 | * @return Swift_Mime_Header |
|
| 185 | */ |
||
| 186 | 33 | public function createPathHeader($name, $path = null) |
|
| 198 | 130 | ||
| 199 | 130 | /** |
|
| 200 | 130 | * Notify this observer that the entity's charset has changed. |
|
| 201 | 130 | * |
|
| 202 | * @param string $charset |
||
| 203 | * |
||
| 204 | * @return bool |
||
| 205 | */ |
||
| 206 | 5 | public function charsetChanged($charset) |
|
| 218 | |||
| 219 | 169 | /** |
|
| 220 | 46 | * Make a deep copy of object. |
|
| 221 | */ |
||
| 222 | 169 | public function __clone() |
|
| 227 | |||
| 228 | /** |
||
| 229 | * Apply the charset to the Header |
||
| 230 | * |
||
| 231 | * @param Swift_Mime_Header $header |
||
| 232 | */ |
||
| 233 | private function _setHeaderCharset(Swift_Mime_Header $header) |
||
| 239 | } |
||
| 240 |
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.