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 |
||
10 | class Cms_admin extends CI_Model |
||
11 | { |
||
|
|||
12 | |||
13 | /* * *********************************************************** |
||
14 | * Pages |
||
15 | * ********************************************************** */ |
||
16 | |||
17 | /** |
||
18 | * Add page into content table |
||
19 | * |
||
20 | * @param array $data |
||
21 | * @return integer |
||
22 | */ |
||
23 | public function add_page($data) { |
||
45 | |||
46 | /** |
||
47 | * Select page by id and lang_id |
||
48 | * |
||
49 | * @param int $id |
||
50 | * @param int $lang |
||
51 | * @return array |
||
52 | */ |
||
53 | public function get_page_by_lang($id, $lang = 0) { |
||
65 | |||
66 | /** |
||
67 | * Select page by id |
||
68 | * |
||
69 | * @param integer $id |
||
70 | * @return array |
||
71 | */ |
||
72 | public function get_page($id) { |
||
83 | |||
84 | /** |
||
85 | * @param integer $id |
||
86 | * @return bool |
||
87 | */ |
||
88 | public function page_exists($id) { |
||
96 | |||
97 | /** |
||
98 | * @param $id |
||
99 | * @param $data |
||
100 | * @param bool $exists |
||
101 | * @return bool |
||
102 | */ |
||
103 | public function update_page($id, $data , $exists = false) { |
||
140 | |||
141 | /** |
||
142 | * Creates new category |
||
143 | * |
||
144 | * @param array $data |
||
145 | * @return int |
||
146 | */ |
||
147 | public function create_category($data) { |
||
153 | |||
154 | /** |
||
155 | * Update category data |
||
156 | * |
||
157 | * @access public |
||
158 | * @param array $data |
||
159 | * @param int $id |
||
160 | */ |
||
161 | public function update_category($data, $id) { |
||
166 | |||
167 | /** |
||
168 | * Select all categories |
||
169 | * |
||
170 | * @access public |
||
171 | * @return array |
||
172 | */ |
||
173 | public function get_categories() { |
||
177 | |||
178 | /** |
||
179 | * Get category by id |
||
180 | * @param int $id |
||
181 | * @return bool|array |
||
182 | */ |
||
183 | View Code Duplication | public function get_category($id) { |
|
194 | |||
195 | /** |
||
196 | * Check if category is created |
||
197 | * |
||
198 | * @access public |
||
199 | * @param string $url |
||
200 | * @return bool |
||
201 | */ |
||
202 | public function is_category($url) { |
||
209 | |||
210 | /* * *********************************************************** |
||
211 | * Settings |
||
212 | * ********************************************************** */ |
||
213 | |||
214 | /** |
||
215 | * Save settings |
||
216 | * |
||
217 | * @settings array |
||
218 | * @access public |
||
219 | * @param array $settings |
||
220 | */ |
||
221 | public function save_settings($settings) { |
||
226 | |||
227 | /** |
||
228 | * Selecting main settings |
||
229 | * |
||
230 | * @access public |
||
231 | * @return array |
||
232 | */ |
||
233 | public function get_settings() { |
||
237 | |||
238 | /** |
||
239 | * Get editor theme |
||
240 | * |
||
241 | * @access public |
||
242 | * @return string |
||
243 | */ |
||
244 | public function editor_theme() { |
||
252 | |||
253 | /* * *********************************************************** |
||
254 | * Languages |
||
255 | * ********************************************************** */ |
||
256 | |||
257 | /** |
||
258 | * Add page into content table |
||
259 | * |
||
260 | * @param array $data |
||
261 | * @return int |
||
262 | */ |
||
263 | public function insert_lang($data) { |
||
269 | |||
270 | /** |
||
271 | * @param bool|false $forShop |
||
272 | * @return array |
||
273 | */ |
||
274 | public function get_langs($forShop = false) { |
||
289 | |||
290 | /** |
||
291 | * @param $id |
||
292 | * @return bool|array |
||
293 | */ |
||
294 | View Code Duplication | public function get_lang($id) { |
|
305 | |||
306 | /** |
||
307 | * @param array $data |
||
308 | * @param int $id |
||
309 | */ |
||
310 | public function update_lang($data, $id) { |
||
315 | |||
316 | /** |
||
317 | * @param integer $id |
||
318 | */ |
||
319 | public function delete_lang($id) { |
||
325 | |||
326 | /** |
||
327 | * @param integer $id |
||
328 | */ |
||
329 | public function set_default_lang($id) { |
||
337 | |||
338 | /** |
||
339 | * @return array |
||
340 | */ |
||
341 | public function get_default_lang() { |
||
349 | |||
350 | } |