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 | const ARRAY_CHUNK_SIZE = 10; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Sync module name. |
||
| 23 | * |
||
| 24 | * @access public |
||
| 25 | * |
||
| 26 | * @return string |
||
| 27 | */ |
||
| 28 | public function name() { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * The id field in the database. |
||
| 34 | * |
||
| 35 | * @access public |
||
| 36 | * |
||
| 37 | * @return string |
||
| 38 | */ |
||
| 39 | public function id_field() { |
||
| 42 | |||
| 43 | /** |
||
| 44 | * The table in the database. |
||
| 45 | * |
||
| 46 | * @access public |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | */ |
||
| 50 | public function table_name() { |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Initialize term relationships action listeners for full sync. |
||
| 56 | * |
||
| 57 | * @access public |
||
| 58 | * |
||
| 59 | * @param callable $callable Action handler callable. |
||
| 60 | */ |
||
| 61 | public function init_full_sync_listeners( $callable ) { |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Initialize the module in the sender. |
||
| 67 | * |
||
| 68 | * @access public |
||
| 69 | */ |
||
| 70 | public function init_before_send() { |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Enqueue the term relationships actions for full sync. |
||
| 77 | * |
||
| 78 | * @access public |
||
| 79 | * |
||
| 80 | * @todo This method has similarities with Automattic\Jetpack\Sync\Modules\Module::enqueue_all_ids_as_action. Refactor to keep DRY. |
||
| 81 | * @see Automattic\Jetpack\Sync\Modules\Module::enqueue_all_ids_as_action |
||
| 82 | * |
||
| 83 | * @param array $config Full sync configuration for this sync module. |
||
| 84 | * @param int $max_items_to_enqueue Maximum number of items to enqueue. |
||
| 85 | * @param int $offset How many items have been enqueued already |
||
| 86 | * @return array Number of actions enqueued, and next module state. |
||
| 87 | */ |
||
| 88 | public function enqueue_full_sync_actions( $config, $max_items_to_enqueue, $offset ) { |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Retrieve chunk IDs with previous interval end. |
||
| 141 | * |
||
| 142 | * @access protected |
||
| 143 | * |
||
| 144 | * @param array $chunks All remaining items. |
||
| 145 | * @param int $previous_interval_end The last item from the previous interval. |
||
|
|
|||
| 146 | * @return array Chunk IDs with the previous interval end. |
||
| 147 | */ |
||
| 148 | View Code Duplication | protected function get_chunks_with_preceding_end( $chunks, $offset ) { |
|
| 158 | |||
| 159 | |||
| 160 | /** |
||
| 161 | * Retrieve an estimated number of actions that will be enqueued. |
||
| 162 | * |
||
| 163 | * @access public |
||
| 164 | * |
||
| 165 | * @param array $config Full sync configuration for this sync module. |
||
| 166 | * @return int Number of items yet to be enqueued. |
||
| 167 | */ |
||
| 168 | public function estimate_full_sync_actions( $config ) { |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Retrieve the actions that will be sent for this module during a full sync. |
||
| 181 | * |
||
| 182 | * @access public |
||
| 183 | * |
||
| 184 | * @return array Full sync actions of this module. |
||
| 185 | */ |
||
| 186 | public function get_full_sync_actions() { |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Expand the term relationships within a hook before they are serialized and sent to the server. |
||
| 192 | * |
||
| 193 | * @access public |
||
| 194 | * |
||
| 195 | * @param array $args The hook parameters. |
||
| 196 | * @return array $args The expanded hook parameters. |
||
| 197 | */ |
||
| 198 | public function expand_term_relationships( $args ) { |
||
| 205 | } |
||
| 206 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.