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 |
||
| 3 | class Jetpack_Full_Sync { |
||
| 4 | |||
| 5 | // writes out a config item for each enabled module containing total items & input config |
||
| 6 | static function start( $modules = null ) { |
||
| 59 | |||
| 60 | static function do_sync() { |
||
| 82 | |||
| 83 | private static function set_config( $config ) { |
||
| 86 | |||
| 87 | private static function get_config() { |
||
| 90 | |||
| 91 | private static function set_status( $status ) { |
||
| 94 | |||
| 95 | private static function get_status() { |
||
| 98 | |||
| 99 | private static function write_option( $name, $value ) { |
||
| 126 | |||
| 127 | private static function read_option( $name ) { |
||
| 139 | |||
| 140 | // private function set_checkout_id( $checkout_id ) { |
||
| 141 | // global $wpdb; |
||
| 142 | |||
| 143 | // $expires = time() + Jetpack_Sync_Defaults::$default_sync_queue_lock_timeout; |
||
| 144 | // $updated_num = $wpdb->query( |
||
| 145 | // $wpdb->prepare( |
||
| 146 | // "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", |
||
| 147 | // "$checkout_id:$expires", |
||
| 148 | // self::get_lock_option_name() |
||
| 149 | // ) |
||
| 150 | // ); |
||
| 151 | |||
| 152 | // if ( ! $updated_num ) { |
||
| 153 | // $updated_num = $wpdb->query( |
||
| 154 | // $wpdb->prepare( |
||
| 155 | // "INSERT INTO $wpdb->options ( option_name, option_value, autoload ) VALUES ( %s, %s, 'no' )", |
||
| 156 | // self::get_lock_option_name(), |
||
| 157 | // "$checkout_id:$expires" |
||
| 158 | // ) |
||
| 159 | // ); |
||
| 160 | // } |
||
| 161 | |||
| 162 | // return $updated_num; |
||
| 163 | // } |
||
| 164 | |||
| 165 | // private function delete_checkout_id() { |
||
| 166 | // global $wpdb; |
||
| 167 | // // rather than delete, which causes fragmentation, we update in place |
||
| 168 | // return $wpdb->query( |
||
| 169 | // $wpdb->prepare( |
||
| 170 | // "UPDATE $wpdb->options SET option_value = %s WHERE option_name = %s", |
||
| 171 | // "0:0", |
||
| 172 | // self::get_lock_option_name() |
||
| 173 | // ) |
||
| 174 | // ); |
||
| 175 | // } |
||
| 176 | } |