Code Duplication    Length = 29-29 lines in 2 locations

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

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

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

@@ 256-284 (lines=29) @@
253
	 *
254
	 * @return array Array of min ID, max ID and total items in the range.
255
	 */
256
	public function get_range( $type ) {
257
		global $wpdb;
258
		if ( ! in_array( $type, array( 'comments', 'posts' ), true ) ) {
259
			return array();
260
		}
261
262
		switch ( $type ) {
263
			case 'posts':
264
				$table     = $wpdb->posts;
265
				$id        = 'ID';
266
				$where_sql = Settings::get_blacklisted_post_types_sql();
267
268
				break;
269
			case 'comments':
270
				$table     = $wpdb->comments;
271
				$id        = 'comment_ID';
272
				$where_sql = Settings::get_comments_filter_sql();
273
				break;
274
		}
275
276
		// TODO: Call $wpdb->prepare on the following query.
277
		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
278
		$results = $wpdb->get_results( "SELECT MAX({$id}) as max, MIN({$id}) as min, COUNT({$id}) as count FROM {$table} WHERE {$where_sql}" );
279
		if ( isset( $results[0] ) ) {
280
			return $results[0];
281
		}
282
283
		return array();
284
	}
285
286
	/**
287
	 * Continue sending instead of enqueueing.