Code Duplication    Length = 28-28 lines in 2 locations

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

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

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