1414use Doctrine \ORM \Query \Parser ;
1515use Doctrine \ORM \Query \ResultSetMapping ;
1616use Doctrine \ORM \QueryBuilder ;
17+ use Doctrine \SqlFormatter \NullHighlighter ;
18+ use Doctrine \SqlFormatter \SqlFormatter ;
1719use Illuminate \Support \Collection ;
1820use Symfony \Component \DependencyInjection \ParameterBag \ContainerBagInterface ;
1921use Symfony \Component \Stopwatch \Stopwatch ;
@@ -118,7 +120,7 @@ public function setResult(
118120 'postsKeyByTypePluralName ' => $ postsKeyByTypePluralName ,
119121 'hasMorePages ' => $ hasMorePages ,
120122 'queryPlan ' => $ queryPlan
121- ] = $ this ->getUnionQueryResult ($ queries , $ orderByDesc , $ maxResults );
123+ ] = $ this ->getUnionQueryResult ($ queries , $ isOrderByDesc , $ maxResults );
122124
123125 $ this ->threads = $ postsKeyByTypePluralName ->get ('threads ' , collect ());
124126 $ this ->replies = $ postsKeyByTypePluralName ->get ('replies ' , collect ());
@@ -147,11 +149,11 @@ public function setResult(
147149 * orderByField: mixed
148150 * }
149151 * @param Collection<Helpecr::POST_TYPE, QueryBuilder> $queries
150- * @param bool $orderByDesc
152+ * @param bool $isOrderByDesc
151153 * @param int $maxResults
152154 * @return array{unionOfQueriesSQL: string, postsKeyByTypePluralName: PostsKeyByTypePluralName, hasMorePages: bool, queryPlan: array}
153155 */
154- private function getUnionQueryResult (Collection $ queries , bool $ orderByDesc , int $ maxResults ): array
156+ private function getUnionQueryResult (Collection $ queries , bool $ isOrderByDesc , int $ maxResults ): array
155157 {
156158 /** @var DBALQueryBuilder $unionOfQueries */
157159 // https://stackoverflow.com/questions/36959801/doctrine-orm-querybuilder-or-dbal-querybuilder
@@ -172,10 +174,10 @@ private function getUnionQueryResult(Collection $queries, bool $orderByDesc, int
172174 $ firstQueryFieldAliases = array_flip ((new Parser ($ firstQuery ->getQuery ()))
173175 ->parse ()->getResultSetMapping ()->scalarMappings );
174176 $ unionOfQueries = $ unionOfQueries
175- ->addOrderBy ($ firstQueryFieldAliases ['orderByField ' ], $ orderByDesc === true ? 'DESC ' : 'ASC ' )
177+ ->addOrderBy ($ firstQueryFieldAliases ['orderByField ' ], $ isOrderByDesc === true ? 'DESC ' : 'ASC ' )
176178 ->addOrderBy ($ firstQueryFieldAliases ['postId ' ])
177179 ->setMaxResults ($ maxResults );
178- $ unionOfQueriesSQL = $ unionOfQueries ->getSQL ();
180+ $ unionOfQueriesSQL = ( new SqlFormatter ( new NullHighlighter ()))-> format ( $ unionOfQueries ->getSQL () );
179181
180182 $ rsm = new ResultSetMapping ();
181183 foreach ($ firstQueryFieldAliases as $ fieldName => $ fieldAlias ) {
0 commit comments