Code Duplication    Length = 29-29 lines in 2 locations

projects/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.

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

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