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 |
||
8 | class IncomingPhysicalMessage |
||
9 | { |
||
10 | /** |
||
11 | * @var string |
||
12 | */ |
||
13 | private $messageId; |
||
14 | |||
15 | /** |
||
16 | * @var array |
||
17 | */ |
||
18 | private $headers; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | private $originalBody; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | private $body; |
||
29 | |||
30 | /** |
||
31 | * @param string $messageId |
||
32 | * @param array $headers |
||
33 | * @param string $body |
||
34 | */ |
||
35 | 14 | View Code Duplication | public function __construct($messageId, array $headers, $body) |
44 | |||
45 | /** |
||
46 | * @return string |
||
47 | */ |
||
48 | 1 | public function getMessageId() |
|
52 | |||
53 | /** |
||
54 | * @return array |
||
55 | */ |
||
56 | 3 | public function getHeaders() |
|
60 | |||
61 | /** |
||
62 | * @return string |
||
63 | */ |
||
64 | 4 | public function getBody() |
|
68 | |||
69 | /** |
||
70 | * @return string|null |
||
71 | */ |
||
72 | 1 | public function getReplyToAddress() |
|
76 | |||
77 | /** |
||
78 | * @param string $name |
||
79 | * @param string $value |
||
80 | */ |
||
81 | 1 | public function setHeader($name, $value) |
|
85 | |||
86 | /** |
||
87 | * @param array $headers |
||
88 | */ |
||
89 | 1 | public function replaceHeaders(array $headers) |
|
93 | |||
94 | /** |
||
95 | * @param string $newBody |
||
96 | */ |
||
97 | 3 | public function replaceBody($newBody) |
|
107 | |||
108 | /** |
||
109 | * Makes sure that the body is reset to the original state as it was when the message was created. |
||
110 | */ |
||
111 | 2 | public function revertToOriginalBodyIfNeeded() |
|
117 | } |
||
118 |