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 ParagraphConverter implements ConverterInterface |
||
8 | { |
||
9 | /** |
||
10 | * @param ElementInterface $element |
||
11 | * |
||
12 | * @return string |
||
13 | */ |
||
14 | 27 | public function convert(ElementInterface $element) |
|
32 | |||
33 | /** |
||
34 | * @return string[] |
||
35 | */ |
||
36 | 78 | public function getSupportedTags() |
|
40 | |||
41 | /** |
||
42 | * @param string $line |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | 27 | private function escapeSpecialCharacters($line) |
|
55 | |||
56 | /** |
||
57 | * @param string $line |
||
58 | * |
||
59 | * @return string |
||
60 | 27 | */ |
|
61 | View Code Duplication | private function escapeBlockquotelikeCharacters($line) |
|
70 | |||
71 | /** |
||
72 | * @param string $line |
||
73 | * |
||
74 | * @return string |
||
75 | 27 | */ |
|
76 | View Code Duplication | private function escapeHeaderlikeCharacters($line) |
|
85 | |||
86 | /** |
||
87 | * @param string $line |
||
88 | * |
||
89 | * @return string |
||
90 | 27 | */ |
|
91 | private function escapeOrderedListlikeCharacters($line) |
||
101 | |||
102 | /** |
||
103 | * @param string $line |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | private function escapeListlikeCharacters($line) |
||
116 | } |
||
117 |
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.