@@ -58,13 +58,13 @@ public function getQueryResult(AbstractQuery $query, int $limit): array
5858 Helper::abortAPIIf (40006 , $ plansCost > $ planCostLimit );
5959 }
6060
61- $ results = collect ($ query ->getResult ());
62- if ($ results ->count () === $ maxResults ) {
63- $ results ->pop ();
61+ $ result = collect ($ query ->getResult ());
62+ if ($ result ->count () === $ maxResults ) {
63+ $ result ->pop ();
6464 $ hasMorePages = true ;
6565 }
6666 return [
67- 'result ' => $ results ,
67+ 'result ' => $ result ,
6868 'hasMorePages ' => $ hasMorePages ?? false ,
6969 'queryPlan ' => $ explainJSON
7070 ];
@@ -75,7 +75,7 @@ public function setResult(
7575 Collection $ queries ,
7676 ?string $ cursorParamValue ,
7777 string $ orderByField ,
78- bool $ orderByDesc ,
78+ bool $ isOrderByDesc ,
7979 Collection $ queryByPostIDParamsName ,
8080 ): void {
8181 $ this ->stopwatch ->start ('setResult ' );
@@ -88,9 +88,9 @@ public function setResult(
8888 }
8989 $ maxResults = $ this ->perPageItems + 1 ;
9090
91- $ queries ->each (function (QueryBuilder $ qb , string $ postType ) use ($ maxResults , $ orderByDesc , $ orderByField , $ cursorsKeyByPostType ) {
91+ $ queries ->each (function (QueryBuilder $ qb , string $ postType ) use ($ maxResults , $ isOrderByDesc , $ orderByField , $ cursorsKeyByPostType ) {
9292 $ qb ->addSelect ("t. $ orderByField AS orderByField " )
93- ->addOrderBy ("t. $ orderByField " , $ orderByDesc === true ? 'DESC ' : 'ASC ' )
93+ ->addOrderBy ("t. $ orderByField " , $ isOrderByDesc === true ? 'DESC ' : 'ASC ' )
9494 // cursor paginator requires values of orderBy column are unique
9595 // if not it should fall back to other unique field (here is the post ID primary key)
9696 // https://use-the-index-luke.com/no-offset
@@ -105,7 +105,7 @@ public function setResult(
105105 return ;
106106 }
107107 $ comparisons = $ cursors ->keys ()->map (
108- fn (string $ fieldName ): Comparison => $ orderByDesc
108+ fn (string $ fieldName ): Comparison => $ isOrderByDesc
109109 ? $ qb ->expr ()->lt ("t. $ fieldName " , ":cursor_ $ fieldName " )
110110 : $ qb ->expr ()->gt ("t. $ fieldName " , ":cursor_ $ fieldName " ),
111111 );
@@ -118,7 +118,7 @@ public function setResult(
118118 'postsKeyByTypePluralName ' => $ postsKeyByTypePluralName ,
119119 'hasMorePages ' => $ hasMorePages ,
120120 'queryPlan ' => $ queryPlan
121- ] = $ this ->getUnionQueryResult ($ queries , $ orderByDesc , $ maxResults );
121+ ] = $ this ->getUnionQueryResult ($ queries , $ isOrderByDesc , $ maxResults );
122122
123123 $ this ->threads = $ postsKeyByTypePluralName ->get ('threads ' , collect ());
124124 $ this ->replies = $ postsKeyByTypePluralName ->get ('replies ' , collect ());
@@ -147,11 +147,11 @@ public function setResult(
147147 * orderByField: mixed
148148 * }
149149 * @param Collection<Helpecr::POST_TYPE, QueryBuilder> $queries
150- * @param bool $orderByDesc
150+ * @param bool $isOrderByDesc
151151 * @param int $maxResults
152152 * @return array{unionOfQueriesSQL: string, postsKeyByTypePluralName: PostsKeyByTypePluralName, hasMorePages: bool, queryPlan: array}
153153 */
154- private function getUnionQueryResult (Collection $ queries , bool $ orderByDesc , int $ maxResults ): array
154+ private function getUnionQueryResult (Collection $ queries , bool $ isOrderByDesc , int $ maxResults ): array
155155 {
156156 /** @var DBALQueryBuilder $unionOfQueries */
157157 // https://stackoverflow.com/questions/36959801/doctrine-orm-querybuilder-or-dbal-querybuilder
@@ -172,7 +172,7 @@ private function getUnionQueryResult(Collection $queries, bool $orderByDesc, int
172172 $ firstQueryFieldAliases = array_flip ((new Parser ($ firstQuery ->getQuery ()))
173173 ->parse ()->getResultSetMapping ()->scalarMappings );
174174 $ unionOfQueries = $ unionOfQueries
175- ->addOrderBy ($ firstQueryFieldAliases ['orderByField ' ], $ orderByDesc === true ? 'DESC ' : 'ASC ' )
175+ ->addOrderBy ($ firstQueryFieldAliases ['orderByField ' ], $ isOrderByDesc === true ? 'DESC ' : 'ASC ' )
176176 ->addOrderBy ($ firstQueryFieldAliases ['postId ' ])
177177 ->setMaxResults ($ maxResults );
178178 $ unionOfQueriesSQL = $ unionOfQueries ->getSQL ();
0 commit comments