@@ -39,7 +39,7 @@ public function __construct()
3939 $ this ->http ->keep_alive = false ;
4040 $ this ->http ->timeout = 30 ;
4141
42- if ($ helper ->getConf ('chroma_apikey ' )) {
42+ if ($ helper ->getConf ('chroma_apikey ' )) {
4343 $ this ->http ->headers ['Authorization ' ] = 'Bearer ' . $ helper ->getConf ('chroma_apikey ' );
4444 }
4545 }
@@ -53,14 +53,14 @@ public function __construct()
5353 * @return mixed
5454 * @throws \Exception
5555 */
56- protected function runQuery ($ endpoint , $ data , $ method = 'POST ' )
56+ protected function runQuery ($ endpoint , mixed $ data , $ method = 'POST ' )
5757 {
5858 $ url = $ this ->baseurl . '/api/v1 ' . $ endpoint . '?tenant= ' . $ this ->tenant . '&database= ' . $ this ->database ;
5959
6060 if (is_array ($ data ) && $ data === []) {
6161 $ json = '{} ' ;
6262 } else {
63- $ json = json_encode ($ data );
63+ $ json = json_encode ($ data, JSON_THROW_ON_ERROR );
6464 }
6565
6666 $ this ->http ->sendRequest ($ url , $ json , $ method );
@@ -71,19 +71,19 @@ protected function runQuery($endpoint, $data, $method = 'POST')
7171 }
7272
7373 try {
74- $ result = json_decode ($ response , true , 512 , JSON_THROW_ON_ERROR );
75- } catch (\Exception $ e ) {
74+ $ result = json_decode (( string ) $ response , true , 512 , JSON_THROW_ON_ERROR );
75+ } catch (\Exception ) {
7676 throw new \Exception ('Chroma API returned invalid JSON. ' . $ response );
7777 }
7878
7979 if ((int )$ this ->http ->status !== 200 ) {
8080 if (isset ($ result ['detail ' ][0 ]['msg ' ])) {
8181 $ error = $ result ['detail ' ][0 ]['msg ' ];
82- } else if (isset ($ result ['detail ' ]['msg ' ])) {
82+ } elseif (isset ($ result ['detail ' ]['msg ' ])) {
8383 $ error = $ result ['detail ' ]['msg ' ];
84- } else if (isset ($ result ['detail ' ]) && is_string ($ result ['detail ' ])) {
84+ } elseif (isset ($ result ['detail ' ]) && is_string ($ result ['detail ' ])) {
8585 $ error = $ result ['detail ' ];
86- } else if (isset ($ result ['error ' ])) {
86+ } elseif (isset ($ result ['error ' ])) {
8787 $ error = $ result ['error ' ];
8888 } else {
8989 $ error = $ this ->http ->error ;
@@ -164,9 +164,7 @@ public function deletePageChunks($page, $firstChunkID)
164164 {
165165 // delete all possible chunk IDs
166166 $ ids = range ($ firstChunkID , $ firstChunkID + 99 , 1 );
167- $ ids = array_map (function ($ id ) {
168- return (string )$ id ;
169- }, $ ids );
167+ $ ids = array_map (static fn ($ id ) => (string )$ id , $ ids );
170168 $ this ->runQuery (
171169 '/collections/ ' . $ this ->getCollectionID () . '/delete ' ,
172170 [
@@ -192,7 +190,6 @@ public function addPageChunks($chunks)
192190 'language ' => $ chunk ->getLanguage ()
193191 ];
194192 $ documents [] = $ chunk ->getText ();
195-
196193 }
197194
198195 $ this ->runQuery (
@@ -222,9 +219,7 @@ public function runMaintenance()
222219 public function getPageChunks ($ page , $ firstChunkID )
223220 {
224221 $ ids = range ($ firstChunkID , $ firstChunkID + 99 , 1 );
225- $ ids = array_map (function ($ id ) {
226- return (string )$ id ;
227- }, $ ids );
222+ $ ids = array_map (static fn ($ id ) => (string )$ id , $ ids );
228223
229224 $ data = $ this ->runQuery (
230225 '/collections/ ' . $ this ->getCollectionID () . '/get ' ,
0 commit comments