From adefb973aa28879dee9acb36f11a2af0d944be34 Mon Sep 17 00:00:00 2001 From: Trent Renshaw Date: Thu, 31 May 2018 15:42:48 +1000 Subject: [PATCH 1/3] Replaced is_array() check and set of $keys in array with cast to array of $keys in array_filter() Replaced assignment of $key and $dir through list() with each() with simply key() and current() per tenkoma's suggestion. Resolves # 11827 each() advances the pointer similar to next() but is being negated this particular case by array_shift() which resets the pointer --- lib/Cake/Model/Datasource/DboSource.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index a8481a38a..40b794dde 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3043,15 +3043,12 @@ class DboSource extends DataSource { * @return string ORDER BY clause */ public function order($keys, $direction = 'ASC', Model $Model = null) { - if (!is_array($keys)) { - $keys = array($keys); - } - - $keys = array_filter($keys); - + $keys = array_filter((array) $keys); + $result = array(); while (!empty($keys)) { - list($key, $dir) = each($keys); + $key = key($keys); + $dir = current($keys); array_shift($keys); if (is_numeric($key)) { From cc9d2fcaa38bfee48bdb87e842ba0b408fb36c32 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Thu, 31 May 2018 20:14:12 +0000 Subject: [PATCH 2/3] Fix phpcs issue. --- lib/Cake/Model/Datasource/DboSource.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 40b794dde..41fb387c0 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3043,7 +3043,7 @@ class DboSource extends DataSource { * @return string ORDER BY clause */ public function order($keys, $direction = 'ASC', Model $Model = null) { - $keys = array_filter((array) $keys); + $keys = array_filter((array)$keys); $result = array(); while (!empty($keys)) { From 99d63752d01290f579c579f1699f4a504d7ceef9 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 6 Jun 2018 22:29:49 -0400 Subject: [PATCH 3/3] Fix failing tests. --- lib/Cake/Model/Datasource/DboSource.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 41fb387c0..cbf5d925c 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -3043,8 +3043,11 @@ class DboSource extends DataSource { * @return string ORDER BY clause */ public function order($keys, $direction = 'ASC', Model $Model = null) { - $keys = array_filter((array)$keys); - + if (!is_array($keys)) { + $keys = array($keys); + } + $keys = array_filter($keys); + $result = array(); while (!empty($keys)) { $key = key($keys);