Code Duplication    Length = 28-28 lines in 2 locations

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

@@ 354-381 (lines=28) @@
351
		return build_query( array( 'value' => urlencode($post[$column]), 'id' => $post['ID'] ) );
352
	}
353
354
	function _build_date_range_query( $column, $range, $where ) {
355
		global $wpdb;
356
357
		switch ( count( $range ) ) {
358
			case 2 :
359
				$where .= $wpdb->prepare(
360
					" AND `$wpdb->posts`.$column >= CAST( %s AS DATETIME ) AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
361
					$range['after'],
362
					$range['before']
363
				);
364
				break;
365
			case 1 :
366
				if ( isset( $range['before'] ) ) {
367
					$where .= $wpdb->prepare(
368
						" AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
369
						$range['before']
370
					);
371
				} else {
372
					$where .= $wpdb->prepare(
373
						" AND `$wpdb->posts`.$column > CAST( %s AS DATETIME ) ",
374
						$range['after']
375
					);
376
				}
377
				break;
378
		}
379
380
		return $where;
381
	}
382
}
383

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

@@ 356-383 (lines=28) @@
353
		return build_query( array( 'value' => urlencode($post[$column]), 'id' => $post['ID'] ) );
354
	}
355
356
	function _build_date_range_query( $column, $range, $where ) {
357
		global $wpdb;
358
359
		switch ( count( $range ) ) {
360
			case 2 :
361
				$where .= $wpdb->prepare(
362
					" AND `$wpdb->posts`.$column >= CAST( %s AS DATETIME ) AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
363
					$range['after'],
364
					$range['before']
365
				);
366
				break;
367
			case 1 :
368
				if ( isset( $range['before'] ) ) {
369
					$where .= $wpdb->prepare(
370
						" AND `$wpdb->posts`.$column < CAST( %s AS DATETIME ) ",
371
						$range['before']
372
					);
373
				} else {
374
					$where .= $wpdb->prepare(
375
						" AND `$wpdb->posts`.$column > CAST( %s AS DATETIME ) ",
376
						$range['after']
377
					);
378
				}
379
				break;
380
		}
381
382
		return $where;
383
	}
384
385
	function handle_date_range( $where ) {
386
		return $this->_build_date_range_query( 'post_date', $this->date_range, $where );