Code Duplication    Length = 29-29 lines in 2 locations

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.

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

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