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 | * Initialize term relationships action listeners for full sync. |
||
| 31 | * |
||
| 32 | * @access public |
||
| 33 | * |
||
| 34 | * @param callable $callable Action handler callable. |
||
| 35 | */ |
||
| 36 | public function init_full_sync_listeners( $callable ) { |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Initialize the module in the sender. |
||
| 42 | * |
||
| 43 | * @access public |
||
| 44 | */ |
||
| 45 | public function init_before_send() { |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Enqueue the term relationships actions for full sync. |
||
| 52 | * |
||
| 53 | * @access public |
||
| 54 | * |
||
| 55 | * @todo This method has similarities with Automattic\Jetpack\Sync\Modules\Module::enqueue_all_ids_as_action. Refactor to keep DRY. |
||
| 56 | * @see Automattic\Jetpack\Sync\Modules\Module::enqueue_all_ids_as_action |
||
| 57 | * |
||
| 58 | * @param array $config Full sync configuration for this sync module. |
||
| 59 | * @param int $max_items_to_enqueue Maximum number of items to enqueue. |
||
| 60 | * @param boolean $state True if full sync has finished enqueueing this module, false otherwise. |
||
| 61 | * @return array Number of actions enqueued, and next module state. |
||
| 62 | */ |
||
| 63 | public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $state ) { |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Retrieve an estimated number of actions that will be enqueued. |
||
| 105 | * |
||
| 106 | * @access public |
||
| 107 | * |
||
| 108 | * @param array $config Full sync configuration for this sync module. |
||
| 109 | * @return int Number of items yet to be enqueued. |
||
| 110 | */ |
||
| 111 | public function estimate_full_sync_actions( $config ) { |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Retrieve the actions that will be sent for this module during a full sync. |
||
| 124 | * |
||
| 125 | * @access public |
||
| 126 | * |
||
| 127 | * @return array Full sync actions of this module. |
||
| 128 | */ |
||
| 129 | public function get_full_sync_actions() { |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Expand the term relationships within a hook before they are serialized and sent to the server. |
||
| 135 | * |
||
| 136 | * @access public |
||
| 137 | * |
||
| 138 | * @param array $args The hook parameters. |
||
| 139 | * @return array $args The expanded hook parameters. |
||
| 140 | */ |
||
| 141 | public function expand_term_relationships( $args ) { |
||
| 149 | } |
||
| 150 |