From 516da27f338d720e657060a56fa9d95e9ca75ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?ANDRE=20s=C3=A9bastien?= <sandre@afi-sa.fr> Date: Tue, 20 Sep 2022 10:58:47 +0200 Subject: [PATCH] order match not necessary --- src/Storm/Query.php | 36 ++++++++++++++-------------- tests/Storm/Test/LoaderQueryTest.php | 34 +++++++++++++------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Storm/Query.php b/src/Storm/Query.php index 682462b4..2619bc5c 100644 --- a/src/Storm/Query.php +++ b/src/Storm/Query.php @@ -67,35 +67,35 @@ class Storm_Query implements Storm_Query_CriteriaInterface { } - public function order(string $key) : self { - $this->_orders [] = Storm_Query_Clause::order($key) + /** + * @param $key_or_clause string|Storm_Query_MatchRating + */ + public function order($key_or_clause) : self { + $this->_orders [] = $this->_order($key_or_clause) ->setOrder(false); return $this; } - public function order_desc(string $key) : self { - $this->_orders [] = Storm_Query_Clause::order($key) + /** + * @param $key_or_clause string|Storm_Query_MatchRating + */ + public function order_desc($key_or_clause) : self { + $this->_orders [] = $this->_order($key_or_clause) ->setOrder(true); return $this; } - public function order_match(Storm_Query_MatchRating $match) : self { - $clause_match = Storm_Query_Clause::match($match); - $this->_orders [] = Storm_Query_Clause::order($match->getKey(), $clause_match) - ->setOrder(false); - - return $this; - } - - - public function order_match_desc(Storm_Query_MatchRating $match) : self { - $clause_match = Storm_Query_Clause::match($match); - $this->_orders [] = Storm_Query_Clause::order($match->getKey(), $clause_match) - ->setOrder(true); + /** + * @param $key_or_clause string|Storm_Query_MatchRating + */ + protected function _order($key_or_clause) : Storm_Query_Clause { + if ($key_or_clause instanceof Storm_Query_MatchRating) + return Storm_Query_Clause::order($key_or_clause->getKey(), + Storm_Query_Clause::match($key_or_clause)); - return $this; + return Storm_Query_Clause::order($key_or_clause); } diff --git a/tests/Storm/Test/LoaderQueryTest.php b/tests/Storm/Test/LoaderQueryTest.php index 38cc360f..b342ef69 100644 --- a/tests/Storm/Test/LoaderQueryTest.php +++ b/tests/Storm/Test/LoaderQueryTest.php @@ -413,8 +413,8 @@ class Storm_Test_LoaderQueryOrderTest extends Storm_Test_LoaderQueryTestCase { /** @test */ public function withMatchClauseOrderShouldReturnMatchOrder() { Storm_Query::from(Storm_Test_Mock_User::class) - ->order_match((new Storm_Query_MatchRating('login, role')) - ->against(['ADMIN', 'INVITE'])) + ->order((new Storm_Query_MatchRating('login, role')) + ->against(['ADMIN', 'INVITE'])) ->fetchAll(); $this->assertEquals(['MATCH(login, role) AGAINST(\'ADMIN INVITE\')'], @@ -425,8 +425,8 @@ class Storm_Test_LoaderQueryOrderTest extends Storm_Test_LoaderQueryTestCase { /** @test */ public function withMatchClauseOrderDescShouldReturnMatchOrder() { Storm_Query::from(Storm_Test_Mock_User::class) - ->order_match_desc((new Storm_Query_MatchBoolean('login, role')) - ->against(['ADMIN', 'INVITE'])) + ->order_desc((new Storm_Query_MatchBoolean('login, role')) + ->against(['ADMIN', 'INVITE'])) ->fetchAll(); $this->assertEquals(['MATCH(login, role) AGAINST(\'ADMIN INVITE\' IN BOOLEAN MODE) desc'], @@ -822,8 +822,8 @@ class Storm_Test_LoaderQueryVolatileClauseOrderTest /** @test */ public function withMatch_Level_Administrateur_ShouldAnswersOrderedUser() { $query = Storm_Query::from(Storm_Test_LoaderQueryUser::class) - ->order_match((new Storm_Query_MatchRating('level')) - ->against('administrateur')); + ->order((new Storm_Query_MatchRating('level')) + ->against('administrateur')); $this->assertEquals(['user_admin', 'user_invite', 'user_administrateur'], (new Storm_Model_Collection($query->fetchAll())) ->collect('login') @@ -834,8 +834,8 @@ class Storm_Test_LoaderQueryVolatileClauseOrderTest /** @test */ public function withMatch_Level_Administrateur_Redacteur_Desc_ShouldAnswersOrderedUser() { $query = Storm_Query::from(Storm_Test_LoaderQueryUser::class) - ->order_match_desc((new Storm_Query_MatchRating('level')) - ->against('administrateur redacteur')); + ->order_desc((new Storm_Query_MatchRating('level')) + ->against('administrateur redacteur')); $this->assertEquals(['user_administrateur', 'user_admin', 'user_invite'], (new Storm_Model_Collection($query->fetchAll())) ->collect('login') @@ -846,8 +846,8 @@ class Storm_Test_LoaderQueryVolatileClauseOrderTest /** @test */ public function withMatchInBooleanMode_Level_Administrateur_Redacteur_Desc_ShouldAnswersOrderedUser() { $query = Storm_Query::from(Storm_Test_LoaderQueryUser::class) - ->order_match_desc((new Storm_Query_MatchBoolean('level')) - ->against('administrateur redacteur')); + ->order_desc((new Storm_Query_MatchBoolean('level')) + ->against('administrateur redacteur')); $this->assertEquals(['user_admin', 'user_administrateur', 'user_invite'], (new Storm_Model_Collection($query->fetchAll())) ->collect('login') @@ -858,10 +858,10 @@ class Storm_Test_LoaderQueryVolatileClauseOrderTest /** @test */ public function withMatch_FooDescExacteInBooleanMode_Forth_Fifth_Level_Administrateur_Redacteur_ShouldAnswersOrderedUser() { $query = Storm_Query::from(Storm_Test_LoaderQueryUser::class) - ->order_match_desc((new Storm_Query_MatchBoolean('foo')) - ->exact('forth fifth')) - ->order_match((new Storm_Query_MatchRating('level')) - ->against('administrateur redacteur')); + ->order_desc((new Storm_Query_MatchBoolean('foo')) + ->exact('forth fifth')) + ->order((new Storm_Query_MatchRating('level')) + ->against('administrateur redacteur')); $this->assertEquals(['user_invite', 'user_admin', 'user_administrateur'], (new Storm_Model_Collection($query->fetchAll())) ->collect('login') @@ -877,9 +877,9 @@ class Storm_Test_LoaderQueryVolatileClauseOrderTest return; $query = Storm_Query::from(Storm_Test_LoaderQueryUser::class) - ->order_match((new Storm_Query_MatchBoolean('foo,level', true)) - ->against('invite redacteur') - ->against('second third')); + ->order((new Storm_Query_MatchBoolean('foo,level', true)) + ->against('invite redacteur') + ->against('second third')); $this->assertEquals([Storm_Test_LoaderQueryUser::find(101), Storm_Test_LoaderQueryUser::find(102), Storm_Test_LoaderQueryUser::find(100)], -- GitLab