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 | View Code Duplication | class OutgoingLogicalMessageMutationContext |
|
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var object |
||
| 11 | */ |
||
| 12 | private $message; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var array |
||
| 16 | */ |
||
| 17 | private $headers; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var bool |
||
| 21 | */ |
||
| 22 | private $hasMessageChanged = false; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param object $message |
||
| 26 | * @param array $headers |
||
| 27 | */ |
||
| 28 | 13 | public function __construct($message, array $headers) |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @return object |
||
| 39 | */ |
||
| 40 | 3 | public function getMessage() |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @return array |
||
| 47 | */ |
||
| 48 | 4 | public function getHeaders() |
|
| 52 | |||
| 53 | /** |
||
| 54 | * @return bool |
||
| 55 | */ |
||
| 56 | 4 | public function hasMessageChanged() |
|
| 60 | |||
| 61 | /** |
||
| 62 | * @param object $message |
||
| 63 | */ |
||
| 64 | 5 | public function updateMessage($message) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * @param string $name |
||
| 75 | * @param string $value |
||
| 76 | */ |
||
| 77 | 2 | public function setHeader($name, $value) |
|
| 81 | } |
||
| 82 |