Code Duplication    Length = 22-22 lines in 2 locations

packages/sync/src/class-replicastore.php 2 locations

@@ 120-141 (lines=22) @@
117
	 * @param int    $max_id Maximum post ID.
118
	 * @return int Number of posts.
119
	 */
120
	public function post_count( $status = null, $min_id = null, $max_id = null ) {
121
		global $wpdb;
122
123
		$where = '';
124
125
		if ( $status ) {
126
			$where = "post_status = '" . esc_sql( $status ) . "'";
127
		} else {
128
			$where = '1=1';
129
		}
130
131
		if ( ! empty( $min_id ) ) {
132
			$where .= ' AND ID >= ' . (int) $min_id;
133
		}
134
135
		if ( ! empty( $max_id ) ) {
136
			$where .= ' AND ID <= ' . (int) $max_id;
137
		}
138
139
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
140
		return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE $where" );
141
	}
142
143
	/**
144
	 * Retrieve the posts with a particular post status.
@@ 301-322 (lines=22) @@
298
	 * @param int    $max_id Maximum comment ID.
299
	 * @return int Number of comments.
300
	 */
301
	public function comment_count( $status = null, $min_id = null, $max_id = null ) {
302
		global $wpdb;
303
304
		$comment_approved = $this->comment_status_to_approval_value( $status );
305
306
		if ( false !== $comment_approved ) {
307
			$where = "comment_approved = '" . esc_sql( $comment_approved ) . "'";
308
		} else {
309
			$where = '1=1';
310
		}
311
312
		if ( ! empty( $min_id ) ) {
313
			$where .= ' AND comment_ID >= ' . (int) $min_id;
314
		}
315
316
		if ( ! empty( $max_id ) ) {
317
			$where .= ' AND comment_ID <= ' . (int) $max_id;
318
		}
319
320
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
321
		return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE $where" );
322
	}
323
324
	/**
325
	 * Translate a comment status to a value of the comment_approved field.