11<?php
2- declare (strict_types= 1 );
2+ declare (strict_types = 1 );
33
44namespace TBolier \RethinkQL \Connection ;
55
@@ -155,7 +155,13 @@ public function continueQuery(int $token): ResponseInterface
155155 */
156156 public function expr (string $ string ): ResponseInterface
157157 {
158- return $ this ->run (new ExprMessage (QueryType::START , 'foo ' ));
158+ $ response = $ this ->run (new ExprMessage (QueryType::START , 'foo ' ));
159+
160+ if ($ response instanceof ResponseInterface) {
161+ return $ response ;
162+ }
163+
164+ return new Response ();
159165 }
160166
161167 /**
@@ -179,7 +185,7 @@ public function run(MessageInterface $message, $raw = false)
179185 $ this ->writeQuery ($ token , $ message );
180186
181187 if ($ this ->noReply ) {
182- return null ;
188+ return new Response () ;
183189 }
184190
185191 $ response = $ this ->receiveResponse ($ token , $ message );
@@ -277,9 +283,9 @@ public function writeQuery(int $token, MessageInterface $message): int
277283 }
278284
279285 $ requestSize = pack ('V ' , \strlen ($ request ));
280- $ binaryToken = pack ('V ' , $ token ) . pack ('V ' , 0 );
286+ $ binaryToken = pack ('V ' , $ token ). pack ('V ' , 0 );
281287
282- return $ this ->stream ->write ($ binaryToken . $ requestSize . $ request );
288+ return $ this ->stream ->write ($ binaryToken. $ requestSize. $ request );
283289 }
284290
285291 /**
@@ -385,27 +391,27 @@ private function validateResponse(
385391 int $ token ,
386392 MessageInterface $ message
387393 ): void {
388- if (! $ response ->getType ()) {
394+ if ($ response ->getType () === null ) {
389395 throw new ConnectionException ('Response message has no type. ' );
390396 }
391397
392398 if ($ response ->getType () === ResponseType::CLIENT_ERROR ) {
393- throw new ConnectionException ('Client error: ' . $ response ->getData ()[0 ] . ' jsonQuery: ' . json_encode ($ message ));
399+ throw new ConnectionException ('Client error: ' . $ response ->getData ()[0 ]. ' jsonQuery: ' . json_encode ($ message ));
394400 }
395401
396402 if ($ responseToken !== $ token ) {
397403 throw new ConnectionException (
398404 'Received wrong token. Response does not match the request. '
399- . 'Expected ' . $ token . ', received ' . $ responseToken
405+ . 'Expected ' . $ token. ', received ' . $ responseToken
400406 );
401407 }
402408
403409 if ($ response ->getType () === ResponseType::COMPILE_ERROR ) {
404- throw new ConnectionException ('Compile error: ' . $ response ->getData ()[0 ] . ', jsonQuery: ' . json_encode ($ message ));
410+ throw new ConnectionException ('Compile error: ' . $ response ->getData ()[0 ]. ', jsonQuery: ' . json_encode ($ message ));
405411 }
406412
407413 if ($ response ->getType () === ResponseType::RUNTIME_ERROR ) {
408- throw new ConnectionException ('Runtime error: ' . $ response ->getData ()[0 ] . ', jsonQuery: ' . json_encode ($ message ));
414+ throw new ConnectionException ('Runtime error: ' . $ response ->getData ()[0 ]. ', jsonQuery: ' . json_encode ($ message ));
409415 }
410416 }
411417}
0 commit comments