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_Sync_Module_Comments extends Jetpack_Sync_Module { |
||
4 | |||
5 | public function name() { |
||
8 | |||
9 | public function init_listeners( $callable ) { |
||
25 | |||
26 | public function init_full_sync_listeners( $callable ) { |
||
29 | |||
30 | public function init_before_send() { |
||
46 | |||
47 | public function enqueue_full_sync_actions( $config ) { |
||
51 | |||
52 | View Code Duplication | public function estimate_full_sync_actions( $config ) { |
|
65 | |||
66 | View Code Duplication | private function get_where_sql( $config ) { |
|
73 | |||
74 | public function get_full_sync_actions() { |
||
77 | |||
78 | public function count_full_sync_actions( $action_names ) { |
||
81 | |||
82 | function expand_wp_comment_status_change( $args ) { |
||
85 | |||
86 | function expand_wp_insert_comment( $args ) { |
||
89 | |||
90 | function filter_comment( $comment ) { |
||
91 | /** |
||
92 | * Filters whether to prevent sending comment data to .com |
||
93 | * |
||
94 | * Passing true to the filter will prevent the comment data from being sent |
||
95 | * to the WordPress.com. |
||
96 | * Instead we pass data that will still enable us to do a checksum against the |
||
97 | * Jetpacks data but will prevent us from displaying the data on in the API as well as |
||
98 | * other services. |
||
99 | * @since 4.2.0 |
||
100 | * |
||
101 | * @param boolean false prevent post data from bing synced to WordPress.com |
||
102 | * @param mixed $comment WP_COMMENT object |
||
103 | */ |
||
104 | if ( apply_filters( 'jetpack_sync_prevent_sending_comment_data', false, $comment ) ) { |
||
105 | $blocked_comment = new stdClass(); |
||
106 | $blocked_comment->comment_ID = $comment->comment_ID; |
||
107 | $blocked_comment->comment_date = $comment->comment_date; |
||
108 | $blocked_comment->comment_date_gmt = $comment->comment_date_gmt; |
||
109 | $blocked_comment->comment_approved = 'jetpack_sync_blocked'; |
||
110 | |||
111 | return $blocked_comment; |
||
112 | } |
||
113 | |||
114 | return $comment; |
||
115 | } |
||
116 | |||
117 | public function expand_comment_ids( $args ) { |
||
129 | } |
||
130 |