From cfd2dda0081189fd3845dfb1d52d7fc7bb204b8e Mon Sep 17 00:00:00 2001 From: Sidsector9 Date: Wed, 25 Oct 2017 08:30:34 +0530 Subject: [PATCH] GH#36 Improvised logic --- inc/class-formatter.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/inc/class-formatter.php b/inc/class-formatter.php index d817392..fa0d5c6 100644 --- a/inc/class-formatter.php +++ b/inc/class-formatter.php @@ -91,19 +91,13 @@ class Formatter { if ( $orderby ) { usort( $items, function( $a, $b ) use ( $order, $orderby ) { - if ( 'ASC' === $order ) { - if ( is_numeric( $a->$orderby ) && is_numeric( $b->$orderby ) ) { - return $this->compare_float( $a->$orderby, $b->$orderby ); - } else { - return strcmp( $a->$orderby, $b->$orderby ); - } - } elseif ( 'DESC' === $order ) { - if ( is_numeric( $b->$orderby ) && is_numeric( $a->$orderby ) ) { - return $this->compare_float( $b->$orderby, $a->$orderby ); - } else { - return strcmp( $b->$orderby, $a->$orderby ); - } + list( $first, $second ) = 'ASC' === $order ? array( $a, $b ) : array( $b, $a ); + + if ( is_numeric( $first->$orderby ) && is_numeric( $second->$orderby ) ) { + return $this->compare_float( $first->$orderby, $second->$orderby ); } + + return strcmp( $first->$orderby, $second->$orderby ); }); }