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 |
||
| 12 | class Mem_cache extends Memcache |
||
| 13 | { |
||
| 14 | |||
| 15 | public $CI; |
||
| 16 | |||
| 17 | public $get = 0; |
||
| 18 | |||
| 19 | public $set = 0; |
||
| 20 | |||
| 21 | public $key_prefix = ''; |
||
| 22 | |||
| 23 | //Cache config |
||
| 24 | public $_Config = [ |
||
| 25 | 'store' => 'cache', |
||
| 26 | 'ttl' => 3600, |
||
| 27 | ]; |
||
| 28 | |||
| 29 | public function __construct() { |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Fetch Cache |
||
| 38 | * |
||
| 39 | * @param string $key |
||
| 40 | * |
||
| 41 | * @return mixed |
||
|
|
|||
| 42 | */ |
||
| 43 | public function fetch($key, $group = FALSE) { |
||
| 51 | |||
| 52 | public function _fetch($key) { |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Fetch cached function |
||
| 63 | */ |
||
| 64 | public function fetch_func($object, $func, $args = []) { |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Store Cache Item |
||
| 75 | * |
||
| 76 | * @param string $key |
||
| 77 | * @param mixed $data |
||
| 78 | * @param int $ttl |
||
| 79 | * |
||
| 80 | * @return bool |
||
| 81 | */ |
||
| 82 | public function store($key, $data, $ttl = false, $group = false) { |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Cache Function |
||
| 96 | * |
||
| 97 | * @return mixed |
||
| 98 | * @access public |
||
| 99 | */ |
||
| 100 | public function call($func = [], $args = [], $ttl = FALSE) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Clean all cache objects |
||
| 127 | * |
||
| 128 | * @return void |
||
| 129 | */ |
||
| 130 | public function Clean() { |
||
| 134 | |||
| 135 | /** |
||
| 136 | * Clean all cache objects |
||
| 137 | * |
||
| 138 | * @return void |
||
| 139 | */ |
||
| 140 | public function delete_group() { |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Delete Cache Item |
||
| 147 | * |
||
| 148 | * @param string $key - cache item key |
||
| 149 | * |
||
| 150 | * @return bool |
||
| 151 | */ |
||
| 152 | public function delete($key) { |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Delete Cached Function |
||
| 159 | * |
||
| 160 | * @return bool |
||
| 161 | */ |
||
| 162 | public function delete_func($object, $func, $args = []) { |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Delete All Cache Items |
||
| 170 | * |
||
| 171 | * @return bool |
||
| 172 | * @access public |
||
| 173 | */ |
||
| 174 | public function delete_all() { |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Generate key |
||
| 181 | * |
||
| 182 | * @param $key |
||
| 183 | * @return string */ |
||
| 184 | public function generatekey($key) { |
||
| 188 | |||
| 189 | } |
||
| 190 | |||
| 191 | /* End of cache.php */ |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.