Code Duplication    Length = 22-22 lines in 2 locations

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

@@ 299-320 (lines=22) @@
296
	 * @param int    $max_id Maximum comment ID.
297
	 * @return int Number of comments.
298
	 */
299
	public function comment_count( $status = null, $min_id = null, $max_id = null ) {
300
		global $wpdb;
301
302
		$comment_approved = $this->comment_status_to_approval_value( $status );
303
304
		if ( false !== $comment_approved ) {
305
			$where = "comment_approved = '" . esc_sql( $comment_approved ) . "'";
306
		} else {
307
			$where = '1=1';
308
		}
309
310
		if ( ! empty( $min_id ) ) {
311
			$where .= ' AND comment_ID >= ' . (int) $min_id;
312
		}
313
314
		if ( ! empty( $max_id ) ) {
315
			$where .= ' AND comment_ID <= ' . (int) $max_id;
316
		}
317
318
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
319
		return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments WHERE $where" );
320
	}
321
322
	/**
323
	 * Translate a comment status to a value of the comment_approved field.
@@ 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.