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 Base extends CI_Model |
||
| 8 | { |
||
|
|
|||
| 9 | |||
| 10 | /** |
||
| 11 | * @var array |
||
| 12 | */ |
||
| 13 | public $comments_product_id = []; |
||
| 14 | |||
| 15 | public function __construct() { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @param int $item_id |
||
| 21 | * @param int $status |
||
| 22 | * @param string $module |
||
| 23 | * @param int $limit |
||
| 24 | * @param string $order_by |
||
| 25 | * @return bool|array |
||
| 26 | */ |
||
| 27 | public function get($item_id, $status = 0, $module, $limit = 999999, $order_by) { |
||
| 47 | |||
| 48 | public function get_one($id) { |
||
| 52 | |||
| 53 | public function add($data) { |
||
| 58 | |||
| 59 | public function all($row_count, $offset) { |
||
| 74 | |||
| 75 | public function get_item_comments_status($item_id) { |
||
| 92 | |||
| 93 | public function update($id, $data = []) { |
||
| 99 | |||
| 100 | View Code Duplication | public function setYes($id) { |
|
| 108 | |||
| 109 | View Code Duplication | public function setNo($id) { |
|
| 117 | |||
| 118 | /** |
||
| 119 | * @param int $id |
||
| 120 | * @return bool |
||
| 121 | */ |
||
| 122 | public function delete($id) { |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param int $id |
||
| 150 | */ |
||
| 151 | public function changeVotesAfterDelete($id) { |
||
| 159 | |||
| 160 | /** |
||
| 161 | * @throws \Propel\Runtime\Exception\PropelException |
||
| 162 | */ |
||
| 163 | public function setVoutesAfterDelete() { |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @param int $status |
||
| 179 | * @return int |
||
| 180 | */ |
||
| 181 | public function count_by_status($status = 0) { |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return array |
||
| 190 | */ |
||
| 191 | public function get_settings() { |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param array $data |
||
| 200 | */ |
||
| 201 | public function save_settings($data) { |
||
| 205 | |||
| 206 | /** |
||
| 207 | * @param array $ids |
||
| 208 | * @return mixed |
||
| 209 | */ |
||
| 210 | public function get_many($ids) { |
||
| 215 | |||
| 216 | } |
||
| 217 | |||
| 218 | /* End of base.php */ |