2323
2424use function assert ;
2525use function count ;
26- use InvalidArgumentException ;
2726use function is_array ;
27+ use MacFJA \RediSearch \Exception \UnexpectedServerResponseException ;
2828use MacFJA \RediSearch \Redis \Command \Option \CustomValidatorOption as CV ;
2929use MacFJA \RediSearch \Redis \Command \Option \FlagOption ;
3030use MacFJA \RediSearch \Redis \Command \Option \NamedOption ;
@@ -302,15 +302,15 @@ public function getSize(): ?int
302302 /**
303303 * @param mixed $data
304304 *
305- * @return mixed| PaginatedResponse
305+ * @return PaginatedResponse
306306 *
307307 * @SuppressWarnings(PHPMD.CyclomaticComplexity)
308308 * @SuppressWarnings(PHPMD.NPathComplexity)
309309 */
310- public function transformParsedResponse ($ data )
310+ public function parseResponse ($ data )
311311 {
312312 if (!is_array ($ data )) {
313- return $ data ;
313+ throw new UnexpectedServerResponseException ( $ data) ;
314314 }
315315
316316 $ totalCount = array_shift ($ data );
@@ -329,7 +329,7 @@ public function transformParsedResponse($data)
329329
330330 $ documents = array_chunk ($ data , $ chunkSize );
331331
332- $ items = array_map (static function ($ document ) use ($ useSortKeys , $ usePayloads , $ useScores , $ noContent ) {
332+ $ items = array_map (static function ($ document ) use ($ data , $ useSortKeys , $ usePayloads , $ useScores , $ noContent ) {
333333 $ hash = array_shift ($ document ) ?? '' ;
334334 $ score = true === $ useScores ? (float ) array_shift ($ document ) : null ;
335335 $ payload = true === $ usePayloads ? array_shift ($ document ) : null ;
@@ -338,7 +338,7 @@ public function transformParsedResponse($data)
338338 $ fields = [];
339339 if (false === $ noContent ) {
340340 if (!(1 === count ($ document ))) {
341- throw new InvalidArgumentException ( );
341+ throw new UnexpectedServerResponseException ( $ data , ' Incomplete response ' );
342342 }
343343 $ rawData = reset ($ document );
344344 assert (is_array ($ rawData ));
0 commit comments