Code Duplication    Length = 22-22 lines in 2 locations

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

@@ 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.
@@ 122-143 (lines=22) @@
119
	 * @param int    $max_id Maximum post ID.
120
	 * @return int Number of posts.
121
	 */
122
	public function post_count( $status = null, $min_id = null, $max_id = null ) {
123
		global $wpdb;
124
125
		$where = '';
126
127
		if ( $status ) {
128
			$where = "post_status = '" . esc_sql( $status ) . "'";
129
		} else {
130
			$where = '1=1';
131
		}
132
133
		if ( ! empty( $min_id ) ) {
134
			$where .= ' AND ID >= ' . (int) $min_id;
135
		}
136
137
		if ( ! empty( $max_id ) ) {
138
			$where .= ' AND ID <= ' . (int) $max_id;
139
		}
140
141
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
142
		return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts WHERE $where" );
143
	}
144
145
	/**
146
	 * Retrieve the posts with a particular post status.