Code Duplication    Length = 21-21 lines in 2 locations

packages/sync/WP_Replicastore.php 2 locations

@@ 40-60 (lines=21) @@
37
		// noop right now
38
	}
39
40
	public function post_count( $status = null, $min_id = null, $max_id = null ) {
41
		global $wpdb;
42
43
		$where = '';
44
45
		if ( $status ) {
46
			$where = "post_status = '" . esc_sql( $status ) . "'";
47
		} else {
48
			$where = '1=1';
49
		}
50
51
		if ( null != $min_id ) {
52
			$where .= ' AND ID >= ' . intval( $min_id );
53
		}
54
55
		if ( null != $max_id ) {
56
			$where .= ' AND ID <= ' . intval( $max_id );
57
		}
58
59
		return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE $where" );
60
	}
61
62
	// TODO: actually use max_id/min_id
63
	public function get_posts( $status = null, $min_id = null, $max_id = null ) {
@@ 156-176 (lines=21) @@
153
		return $this->table_checksum( $wpdb->postmeta, Defaults::$default_post_meta_checksum_columns, 'meta_id', Settings::get_whitelisted_post_meta_sql(), $min_id, $max_id );
154
	}
155
156
	public function comment_count( $status = null, $min_id = null, $max_id = null ) {
157
		global $wpdb;
158
159
		$comment_approved = $this->comment_status_to_approval_value( $status );
160
161
		if ( $comment_approved !== false ) {
162
			$where = "comment_approved = '" . esc_sql( $comment_approved ) . "'";
163
		} else {
164
			$where = '1=1';
165
		}
166
167
		if ( $min_id != null ) {
168
			$where .= ' AND comment_ID >= ' . intval( $min_id );
169
		}
170
171
		if ( $max_id != null ) {
172
			$where .= ' AND comment_ID <= ' . intval( $max_id );
173
		}
174
175
		return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE $where" );
176
	}
177
178
	private function comment_status_to_approval_value( $status ) {
179
		switch ( $status ) {