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 OutgoingPhysicalMessageMutationContext |
|
8 | { |
||
9 | /** |
||
10 | * @var string |
||
11 | */ |
||
12 | private $body; |
||
13 | |||
14 | /** |
||
15 | * @var array |
||
16 | */ |
||
17 | private $headers; |
||
18 | |||
19 | /** |
||
20 | * @param string $body |
||
21 | * @param array $headers |
||
22 | */ |
||
23 | 8 | public function __construct($body, array $headers) |
|
30 | |||
31 | /** |
||
32 | * @return string |
||
33 | */ |
||
34 | 3 | public function getBody() |
|
38 | |||
39 | /** |
||
40 | * @param string $newBody |
||
41 | */ |
||
42 | 2 | public function replaceBody($newBody) |
|
48 | |||
49 | /** |
||
50 | * @return array |
||
51 | */ |
||
52 | 3 | public function getHeaders() |
|
56 | |||
57 | /** |
||
58 | * @param string $name |
||
59 | * @param string $value |
||
60 | */ |
||
61 | 1 | public function setHeader($name, $value) |
|
65 | } |
||
66 |