Code Duplication    Length = 28-28 lines in 2 locations

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

@@ 412-439 (lines=28) @@
409
		return build_query( array( 'value' => urlencode($post[$column]), 'id' => $post['ID'] ) );
410
	}
411
412
	function _build_date_range_query( $column, $range, $where ) {
413
		global $wpdb;
414
415
		switch ( count( $range ) ) {
416
			case 2 :
417
				$where .= $wpdb->prepare(
418
					" AND `$wpdb->posts`.$column >= CAST( %s AS DATETIME ) AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
419
					$range['after'],
420
					$range['before']
421
				);
422
				break;
423
			case 1 :
424
				if ( isset( $range['before'] ) ) {
425
					$where .= $wpdb->prepare(
426
						" AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
427
						$range['before']
428
					);
429
				} else {
430
					$where .= $wpdb->prepare(
431
						" AND `$wpdb->posts`.$column > CAST( %s AS DATETIME ) ",
432
						$range['after']
433
					);
434
				}
435
				break;
436
		}
437
438
		return $where;
439
	}
440
441
	function handle_date_range( $where ) {
442
		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

@@ 405-432 (lines=28) @@
402
		return build_query( array( 'value' => urlencode($post[$column]), 'id' => $post['ID'] ) );
403
	}
404
405
	function _build_date_range_query( $column, $range, $where ) {
406
		global $wpdb;
407
408
		switch ( count( $range ) ) {
409
			case 2 :
410
				$where .= $wpdb->prepare(
411
					" AND `$wpdb->posts`.$column >= CAST( %s AS DATETIME ) AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
412
					$range['after'],
413
					$range['before']
414
				);
415
				break;
416
			case 1 :
417
				if ( isset( $range['before'] ) ) {
418
					$where .= $wpdb->prepare(
419
						" AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
420
						$range['before']
421
					);
422
				} else {
423
					$where .= $wpdb->prepare(
424
						" AND `$wpdb->posts`.$column > CAST( %s AS DATETIME ) ",
425
						$range['after']
426
					);
427
				}
428
				break;
429
		}
430
431
		return $where;
432
	}
433
}
434