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 |
||
27 | View Code Duplication | class XoopsFormTinymce4Bootstrap extends XoopsEditor |
|
|
|||
28 | { |
||
29 | public $language; |
||
30 | public $width = '100%'; |
||
31 | public $height = '500px'; |
||
32 | |||
33 | public $editor; |
||
34 | |||
35 | /** |
||
36 | * Constructor |
||
37 | * |
||
38 | * @param array $configs Editor Options |
||
39 | */ |
||
40 | |||
41 | public function __construct($configs) |
||
60 | |||
61 | /** |
||
62 | * Renders the Javascript function needed for client-side for validation |
||
63 | * |
||
64 | * I'VE USED THIS EXAMPLE TO WRITE VALIDATION CODE |
||
65 | * http://tinymce.moxiecode.com/punbb/viewtopic.php?id=12616 |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | |||
70 | public function renderValidationJS() |
||
86 | |||
87 | /** |
||
88 | * get language |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | |||
93 | public function getLanguage() |
||
109 | |||
110 | public function getFonts() |
||
118 | |||
119 | /** |
||
120 | * prepare HTML for output |
||
121 | * |
||
122 | * @return sting HTML |
||
123 | */ |
||
124 | |||
125 | public function render() |
||
132 | |||
133 | /** |
||
134 | * Check if compatible |
||
135 | * |
||
136 | * @return bool |
||
137 | */ |
||
138 | |||
139 | public function isActive() |
||
143 | } |
||
144 | |||
145 |
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.