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 |
||
| 7 | class OutgoingPhysicalMessage |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | private $messageId; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $headers; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $body; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param string $messageId |
||
| 26 | * @param array $headers |
||
| 27 | * @param string $body |
||
| 28 | */ |
||
| 29 | 33 | View Code Duplication | public function __construct($messageId, array $headers, $body) |
| 38 | |||
| 39 | /** |
||
| 40 | * @return string |
||
| 41 | */ |
||
| 42 | 1 | public function getMessageId() |
|
| 46 | |||
| 47 | /** |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | 4 | public function getHeaders() |
|
| 54 | |||
| 55 | /** |
||
| 56 | * @param string $name |
||
| 57 | * @param string $value |
||
| 58 | */ |
||
| 59 | 2 | public function setHeader($name, $value) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * @param array $headers |
||
| 66 | */ |
||
| 67 | 1 | public function replaceHeaders(array $headers) |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @return string |
||
| 74 | */ |
||
| 75 | 4 | public function getBody() |
|
| 79 | |||
| 80 | /** |
||
| 81 | * @param string $body |
||
| 82 | */ |
||
| 83 | 2 | public function replaceBody($body) |
|
| 89 | } |
||
| 90 |