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 |
||
| 17 | class Term_Relationships extends Module { |
||
| 18 | /** |
||
| 19 | * Sync module name. |
||
| 20 | * |
||
| 21 | * @access public |
||
| 22 | * |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | public function name() { |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The id field in the database. |
||
| 31 | * |
||
| 32 | * @access public |
||
| 33 | * |
||
| 34 | * @return string |
||
| 35 | */ |
||
| 36 | public function id_field() { |
||
| 39 | |||
| 40 | /** |
||
| 41 | * The table in the database. |
||
| 42 | * |
||
| 43 | * @access public |
||
| 44 | * |
||
| 45 | * @return string |
||
| 46 | */ |
||
| 47 | public function table_name() { |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Initialize term relationships action listeners for full sync. |
||
| 53 | * |
||
| 54 | * @access public |
||
| 55 | * |
||
| 56 | * @param callable $callable Action handler callable. |
||
| 57 | */ |
||
| 58 | public function init_full_sync_listeners( $callable ) { |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Initialize the module in the sender. |
||
| 64 | * |
||
| 65 | * @access public |
||
| 66 | */ |
||
| 67 | public function init_before_send() { |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Enqueue the term relationships actions for full sync. |
||
| 74 | * |
||
| 75 | * @access public |
||
| 76 | * |
||
| 77 | * @todo This method has similarities with Automattic\Jetpack\Sync\Modules\Module::enqueue_all_ids_as_action. Refactor to keep DRY. |
||
| 78 | * @see Automattic\Jetpack\Sync\Modules\Module::enqueue_all_ids_as_action |
||
| 79 | * |
||
| 80 | * @param array $config Full sync configuration for this sync module. |
||
| 81 | * @param int $max_items_to_enqueue Maximum number of items to enqueue. |
||
| 82 | * @param boolean $state True if full sync has finished enqueueing this module, false otherwise. |
||
| 83 | * @return array Number of actions enqueued, and next module state. |
||
| 84 | */ |
||
| 85 | public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Retrieve an estimated number of actions that will be enqueued. |
||
| 127 | * |
||
| 128 | * @access public |
||
| 129 | * |
||
| 130 | * @param array $config Full sync configuration for this sync module. |
||
| 131 | * @return int Number of items yet to be enqueued. |
||
| 132 | */ |
||
| 133 | public function estimate_full_sync_actions( $config ) { |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Retrieve the actions that will be sent for this module during a full sync. |
||
| 146 | * |
||
| 147 | * @access public |
||
| 148 | * |
||
| 149 | * @return array Full sync actions of this module. |
||
| 150 | */ |
||
| 151 | public function get_full_sync_actions() { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Expand the term relationships within a hook before they are serialized and sent to the server. |
||
| 157 | * |
||
| 158 | * @access public |
||
| 159 | * |
||
| 160 | * @param array $args The hook parameters. |
||
| 161 | * @return array $args The expanded hook parameters. |
||
| 162 | */ |
||
| 163 | public function expand_term_relationships( $args ) { |
||
| 171 | } |
||
| 172 |