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) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Create a new Mailbox Header with a list of $addresses. |
||
| 64 | * |
||
| 65 | * @param string $name |
||
| 66 | * @param array|string|null $addresses |
||
| 67 | * |
||
| 68 | * @return Swift_Mime_Header |
||
| 69 | */ |
||
| 70 | 114 | public function createMailboxHeader($name, $addresses = null) |
|
| 80 | |||
| 81 | /** |
||
| 82 | * Create a new Date header using $timestamp (UNIX time). |
||
| 83 | * |
||
| 84 | * @param string $name |
||
| 85 | * @param int|null $timestamp |
||
| 86 | * |
||
| 87 | * @return Swift_Mime_Header |
||
| 88 | */ |
||
| 89 | 112 | public function createDateHeader($name, $timestamp = null) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * Create a new basic text header with $name and $value. |
||
| 102 | * |
||
| 103 | * @param string $name |
||
| 104 | * @param string $value |
||
| 105 | * |
||
| 106 | * @return Swift_Mime_Header |
||
| 107 | */ |
||
| 108 | 152 | public function createTextHeader($name, $value = null) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Create a new ParameterizedHeader with $name, $value and $params. |
||
| 121 | * |
||
| 122 | * @param string $name |
||
| 123 | * @param string $value |
||
| 124 | * @param array $params |
||
| 125 | * |
||
| 126 | * @return Swift_Mime_ParameterizedHeader |
||
| 127 | */ |
||
| 128 | 147 | public function createParameterizedHeader($name, $value = null, $params = array()) |
|
| 150 | |||
| 151 | /** |
||
| 152 | * Create a new ID header for Message-ID or Content-ID. |
||
| 153 | * |
||
| 154 | * @param string $name |
||
| 155 | * @param string|array $ids |
||
| 156 | * |
||
| 157 | * @return Swift_Mime_Header |
||
| 158 | */ |
||
| 159 | 124 | View Code Duplication | public function createIdHeader($name, $ids = null) |
| 171 | |||
| 172 | /** |
||
| 173 | * Create a new Path header with an address (path) in it. |
||
| 174 | * |
||
| 175 | * @param string $name |
||
| 176 | * @param string $path |
||
| 177 | * |
||
| 178 | * @return Swift_Mime_Header |
||
| 179 | */ |
||
| 180 | 33 | View Code Duplication | public function createPathHeader($name, $path = null) |
| 190 | |||
| 191 | /** |
||
| 192 | * Notify this observer that the entity's charset has changed. |
||
| 193 | * |
||
| 194 | * @param string $charset |
||
| 195 | */ |
||
| 196 | 130 | public function charsetChanged($charset) |
|
| 202 | |||
| 203 | /** |
||
| 204 | * Make a deep copy of object. |
||
| 205 | */ |
||
| 206 | 5 | public function __clone() |
|
| 211 | |||
| 212 | /** |
||
| 213 | * Apply the charset to the Header |
||
| 214 | * |
||
| 215 | * @param Swift_Mime_Header $header |
||
| 216 | */ |
||
| 217 | 169 | private function _setHeaderCharset(Swift_Mime_Header $header) |
|
| 223 | } |
||
| 224 |
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.