Code Duplication    Length = 29-29 lines in 2 locations

packages/sync/src/modules/class-full-sync-immediately.php 1 location

@@ 288-316 (lines=29) @@
285
	 *
286
	 * @return array Array of min ID, max ID and total items in the range.
287
	 */
288
	public function get_range( $type ) {
289
		global $wpdb;
290
		if ( ! in_array( $type, array( 'comments', 'posts' ), true ) ) {
291
			return array();
292
		}
293
294
		switch ( $type ) {
295
			case 'posts':
296
				$table     = $wpdb->posts;
297
				$id        = 'ID';
298
				$where_sql = Settings::get_blacklisted_post_types_sql();
299
300
				break;
301
			case 'comments':
302
				$table     = $wpdb->comments;
303
				$id        = 'comment_ID';
304
				$where_sql = Settings::get_comments_filter_sql();
305
				break;
306
		}
307
308
		// TODO: Call $wpdb->prepare on the following query.
309
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
310
		$results = $wpdb->get_results( "SELECT MAX({$id}) as max, MIN({$id}) as min, COUNT({$id}) as count FROM {$table} WHERE {$where_sql}" );
311
		if ( isset( $results[0] ) ) {
312
			return $results[0];
313
		}
314
315
		return array();
316
	}
317
318
	/**
319
	 * Continue sending instead of enqueueing.

packages/sync/src/modules/class-full-sync.php 1 location

@@ 304-332 (lines=29) @@
301
	 * @param string $type Type of sync item to get the range for.
302
	 * @return array Array of min ID, max ID and total items in the range.
303
	 */
304
	public function get_range( $type ) {
305
		global $wpdb;
306
		if ( ! in_array( $type, array( 'comments', 'posts' ), true ) ) {
307
			return array();
308
		}
309
310
		switch ( $type ) {
311
			case 'posts':
312
				$table     = $wpdb->posts;
313
				$id        = 'ID';
314
				$where_sql = Settings::get_blacklisted_post_types_sql();
315
316
				break;
317
			case 'comments':
318
				$table     = $wpdb->comments;
319
				$id        = 'comment_ID';
320
				$where_sql = Settings::get_comments_filter_sql();
321
				break;
322
		}
323
324
		// TODO: Call $wpdb->prepare on the following query.
325
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
326
		$results = $wpdb->get_results( "SELECT MAX({$id}) as max, MIN({$id}) as min, COUNT({$id}) as count FROM {$table} WHERE {$where_sql}" );
327
		if ( isset( $results[0] ) ) {
328
			return $results[0];
329
		}
330
331
		return array();
332
	}
333
334
	/**
335
	 * Get the range for content (posts and comments) to sync.