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 |
||
15 | class Basic extends HTMLModuleAbstract{ |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $tags = [ |
||
21 | 'noparse', 'nobb', 'color', 'font', 'size','br', 'hr', 'clear','img', 'url', 'c', 'list', |
||
22 | 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', |
||
23 | 'strong', 'sub', 'sup', 'del', 'small', 'em', 's', 'b', 'u', 'i', 'tt', |
||
24 | ]; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $singletags = ['br', 'hr', 'clear']; |
||
30 | |||
31 | /** |
||
32 | * @var array |
||
33 | */ |
||
34 | protected $noparse = ['noparse', 'nobb', 'c']; |
||
35 | |||
36 | /** |
||
37 | * @return string |
||
38 | */ |
||
39 | protected function transform():string{ |
||
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | protected function nobb():string{ |
||
54 | |||
55 | /** |
||
56 | * @return string |
||
57 | */ |
||
58 | protected function noparse():string{ |
||
63 | |||
64 | /** |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function c(){ // @todo |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | protected function color(){ |
||
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | protected function font(){ // @todo: restrict fonts via classname |
||
86 | |||
87 | /** |
||
88 | * @return string |
||
89 | */ |
||
90 | protected function size(){ // @todo: restrict sizes via css |
||
93 | |||
94 | /** |
||
95 | * @return string |
||
96 | */ |
||
97 | public function br():string{ // @todo: adjust padding-bottom |
||
100 | |||
101 | /** |
||
102 | * @return string |
||
103 | */ |
||
104 | public function hr():string{ // @todo line style |
||
107 | |||
108 | /** |
||
109 | * @return string |
||
110 | */ |
||
111 | protected function clear(){ |
||
114 | |||
115 | /** |
||
116 | * @return string |
||
117 | */ |
||
118 | View Code Duplication | protected function img():string{ |
|
127 | |||
128 | /** |
||
129 | * @return string |
||
130 | */ |
||
131 | protected function url():string{ |
||
144 | |||
145 | /** |
||
146 | * @return string |
||
147 | */ |
||
148 | protected function list():string{ |
||
178 | |||
179 | } |
||
180 |
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.