Code Duplication    Length = 28-28 lines in 2 locations

json-endpoints/class.wpcom-json-api-list-posts-v1-1-endpoint.php 1 location

@@ 436-463 (lines=28) @@
433
		);
434
	}
435
436
	function _build_date_range_query( $column, $range, $where ) {
437
		global $wpdb;
438
439
		switch ( count( $range ) ) {
440
			case 2:
441
				$where .= $wpdb->prepare(
442
					" AND `$wpdb->posts`.$column >= CAST( %s AS DATETIME ) AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
443
					$range['after'],
444
					$range['before']
445
				);
446
				break;
447
			case 1:
448
				if ( isset( $range['before'] ) ) {
449
					$where .= $wpdb->prepare(
450
						" AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
451
						$range['before']
452
					);
453
				} else {
454
					$where .= $wpdb->prepare(
455
						" AND `$wpdb->posts`.$column > CAST( %s AS DATETIME ) ",
456
						$range['after']
457
					);
458
				}
459
				break;
460
		}
461
462
		return $where;
463
	}
464
465
	function handle_date_range( $where ) {
466
		return $this->_build_date_range_query( 'post_date_gmt', $this->date_range, $where );

json-endpoints/class.wpcom-json-api-list-posts-v1-2-endpoint.php 1 location

@@ 431-458 (lines=28) @@
428
		);
429
	}
430
431
	function _build_date_range_query( $column, $range, $where ) {
432
		global $wpdb;
433
434
		switch ( count( $range ) ) {
435
			case 2:
436
				$where .= $wpdb->prepare(
437
					" AND `$wpdb->posts`.$column >= CAST( %s AS DATETIME ) AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
438
					$range['after'],
439
					$range['before']
440
				);
441
				break;
442
			case 1:
443
				if ( isset( $range['before'] ) ) {
444
					$where .= $wpdb->prepare(
445
						" AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
446
						$range['before']
447
					);
448
				} else {
449
					$where .= $wpdb->prepare(
450
						" AND `$wpdb->posts`.$column > CAST( %s AS DATETIME ) ",
451
						$range['after']
452
					);
453
				}
454
				break;
455
		}
456
457
		return $where;
458
	}
459
}
460