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) { |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Select page by id and lang_id |
||
| 49 | * |
||
| 50 | * @param int $id |
||
| 51 | * @param int $lang |
||
| 52 | * @return array|bool |
||
| 53 | */ |
||
| 54 | public function get_page_by_lang($id, $lang = 0) { |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Select page by id |
||
| 69 | * |
||
| 70 | * @param integer $id |
||
| 71 | * @return array|bool |
||
| 72 | */ |
||
| 73 | View Code Duplication | public function get_page($id) { |
|
| 87 | |||
| 88 | /** |
||
| 89 | * @param integer $id |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | public function page_exists($id) { |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @param int $id |
||
| 103 | * @param array $data |
||
| 104 | * @param bool $exists |
||
| 105 | * @return bool |
||
|
|
|||
| 106 | */ |
||
| 107 | public function update_page($id, $data, $exists = false) { |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Creates new category |
||
| 131 | * |
||
| 132 | * @param array $data |
||
| 133 | * @return int |
||
| 134 | */ |
||
| 135 | public function create_category($data) { |
||
| 142 | |||
| 143 | /** |
||
| 144 | * Update category data |
||
| 145 | * |
||
| 146 | * @access public |
||
| 147 | * @param array $data |
||
| 148 | * @param int $id |
||
| 149 | */ |
||
| 150 | public function update_category($data, $id) { |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Select all categories |
||
| 159 | * |
||
| 160 | * @access public |
||
| 161 | * @return array |
||
| 162 | */ |
||
| 163 | public function get_categories() { |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Get category by id |
||
| 170 | * @param int $id |
||
| 171 | * @return bool|array |
||
| 172 | */ |
||
| 173 | View Code Duplication | public function get_category($id) { |
|
| 186 | |||
| 187 | /** |
||
| 188 | * Check if category is created |
||
| 189 | * |
||
| 190 | * @access public |
||
| 191 | * @param string $url |
||
| 192 | * @return bool |
||
| 193 | */ |
||
| 194 | public function is_category($url) { |
||
| 201 | |||
| 202 | /* * *********************************************************** |
||
| 203 | * Settings |
||
| 204 | * ********************************************************** */ |
||
| 205 | |||
| 206 | /** |
||
| 207 | * Save settings |
||
| 208 | * |
||
| 209 | * @settings array |
||
| 210 | * @access public |
||
| 211 | * @param array $settings |
||
| 212 | */ |
||
| 213 | public function save_settings($settings) { |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Selecting main settings |
||
| 221 | * |
||
| 222 | * @access public |
||
| 223 | * @return array |
||
| 224 | */ |
||
| 225 | public function get_settings() { |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Get editor theme |
||
| 232 | * |
||
| 233 | * @access public |
||
| 234 | * @return string |
||
| 235 | */ |
||
| 236 | public function editor_theme() { |
||
| 244 | |||
| 245 | /* * *********************************************************** |
||
| 246 | * Languages |
||
| 247 | * ********************************************************** */ |
||
| 248 | |||
| 249 | /** |
||
| 250 | * Add page into content table |
||
| 251 | * |
||
| 252 | * @param array $data |
||
| 253 | * @return int |
||
| 254 | */ |
||
| 255 | public function insert_lang($data) { |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @param bool|false $forShop |
||
| 264 | * @return array |
||
| 265 | */ |
||
| 266 | public function get_langs($forShop = false) { |
||
| 281 | |||
| 282 | /** |
||
| 283 | * @param $id |
||
| 284 | * @return bool|array |
||
| 285 | */ |
||
| 286 | public function get_lang($id) { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * @param array $data |
||
| 300 | * @param int $id |
||
| 301 | */ |
||
| 302 | public function update_lang($data, $id) { |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @param integer $id |
||
| 310 | */ |
||
| 311 | public function delete_lang($id) { |
||
| 317 | |||
| 318 | /** |
||
| 319 | * @param integer $id |
||
| 320 | */ |
||
| 321 | public function set_default_lang($id) { |
||
| 329 | |||
| 330 | /** |
||
| 331 | * @return array |
||
| 332 | */ |
||
| 333 | public function get_default_lang() { |
||
| 341 | |||
| 342 | } |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.