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 |
||
22 | class Index implements Annotation |
||
23 | { |
||
24 | /** @var string */ |
||
25 | public $name; |
||
26 | |||
27 | /** @var string */ |
||
28 | public $translogDurability; |
||
29 | |||
30 | /** @var string */ |
||
31 | public $translogSyncInterval; |
||
32 | |||
33 | /** @var string */ |
||
34 | public $translogFlushThreshouldSize; |
||
35 | |||
36 | /** @var string */ |
||
37 | public $refreshInterval; |
||
38 | |||
39 | /** |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getName() |
||
46 | |||
47 | /** |
||
48 | * @param string $name |
||
49 | * @return Index |
||
50 | */ |
||
51 | public function setName($name) |
||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | public function getTranslogDurability() |
||
64 | |||
65 | /** |
||
66 | * @param string $translogDurability |
||
67 | * @return Index |
||
68 | */ |
||
69 | public function setTranslogDurability($translogDurability) |
||
74 | |||
75 | /** |
||
76 | * @return string |
||
77 | */ |
||
78 | public function getTranslogSyncInterval() |
||
82 | |||
83 | /** |
||
84 | * @param string $translogSyncInterval |
||
85 | * @return Index |
||
86 | */ |
||
87 | public function setTranslogSyncInterval($translogSyncInterval) |
||
92 | |||
93 | /** |
||
94 | * @return string |
||
95 | */ |
||
96 | public function getTranslogFlushThreshouldSize() |
||
100 | |||
101 | /** |
||
102 | * @param string $translogFlushThreshouldSize |
||
103 | * @return Index |
||
104 | */ |
||
105 | public function setTranslogFlushThreshouldSize($translogFlushThreshouldSize) |
||
110 | |||
111 | public function isValid() |
||
115 | |||
116 | View Code Duplication | public function getErrorMessage() { |
|
125 | |||
126 | public function getArrayCopy() { |
||
139 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.