11<?php
2- declare (strict_types = 1 );
2+ declare (strict_types= 1 );
33
44namespace TBolier \RethinkQL \Connection ;
55
@@ -132,10 +132,7 @@ public function reconnect($noreplyWait = true): Connection
132132 */
133133 public function continueQuery (int $ token ): ResponseInterface
134134 {
135- $ message = (new Message ())->setQuery (
136- [QueryType::CONTINUE ]
137- );
138-
135+ $ message = new Message (QueryType::CONTINUE );
139136 $ this ->writeQuery ($ token , $ message );
140137
141138 // Await the response
@@ -224,10 +221,10 @@ public function server(): ResponseInterface
224221 try {
225222 $ token = $ this ->generateToken ();
226223
227- $ query = new Message (QueryType::SERVER_INFO );
228- $ this ->writeQuery ($ token , $ query );
224+ $ message = new Message (QueryType::SERVER_INFO );
225+ $ this ->writeQuery ($ token , $ message );
229226
230- $ response = $ this ->receiveResponse ($ token , $ query );
227+ $ response = $ this ->receiveResponse ($ token , $ message );
231228
232229 if ($ response ->getType () !== 5 ) {
233230 throw new ConnectionException ('Unexpected response type for server query. ' );
@@ -245,9 +242,7 @@ public function server(): ResponseInterface
245242 */
246243 public function stopQuery (int $ token ): ResponseInterface
247244 {
248- $ message = (new Message ())->setQuery (
249- [QueryType::STOP ]
250- );
245+ $ message = new Message (QueryType::STOP );
251246
252247 $ this ->writeQuery ($ token , $ message );
253248
@@ -283,9 +278,9 @@ public function writeQuery(int $token, MessageInterface $message): int
283278 }
284279
285280 $ requestSize = pack ('V ' , \strlen ($ request ));
286- $ binaryToken = pack ('V ' , $ token ). pack ('V ' , 0 );
281+ $ binaryToken = pack ('V ' , $ token ) . pack ('V ' , 0 );
287282
288- return $ this ->stream ->write ($ binaryToken. $ requestSize. $ request );
283+ return $ this ->stream ->write ($ binaryToken . $ requestSize . $ request );
289284 }
290285
291286 /**
@@ -298,10 +293,10 @@ public function noreplyWait(): void
298293 try {
299294 $ token = $ this ->generateToken ();
300295
301- $ query = new Message (QueryType::NOREPLY_WAIT );
302- $ this ->writeQuery ($ token , $ query );
296+ $ message = new Message (QueryType::NOREPLY_WAIT );
297+ $ this ->writeQuery ($ token , $ message );
303298
304- $ response = $ this ->receiveResponse ($ token , $ query );
299+ $ response = $ this ->receiveResponse ($ token , $ message );
305300
306301 if ($ response ->getType () !== 4 ) {
307302 throw new ConnectionException ('Unexpected response type for noreplyWait query. ' );
@@ -396,22 +391,22 @@ private function validateResponse(
396391 }
397392
398393 if ($ response ->getType () === ResponseType::CLIENT_ERROR ) {
399- throw new ConnectionException ('Client error: ' . $ response ->getData ()[0 ]. ' jsonQuery: ' . json_encode ($ message ));
394+ throw new ConnectionException ('Client error: ' . $ response ->getData ()[0 ] . ' jsonQuery: ' . json_encode ($ message ));
400395 }
401396
402397 if ($ responseToken !== $ token ) {
403398 throw new ConnectionException (
404399 'Received wrong token. Response does not match the request. '
405- . 'Expected ' . $ token. ', received ' . $ responseToken
400+ . 'Expected ' . $ token . ', received ' . $ responseToken
406401 );
407402 }
408403
409404 if ($ response ->getType () === ResponseType::COMPILE_ERROR ) {
410- throw new ConnectionException ('Compile error: ' . $ response ->getData ()[0 ]. ', jsonQuery: ' . json_encode ($ message ));
405+ throw new ConnectionException ('Compile error: ' . $ response ->getData ()[0 ] . ', jsonQuery: ' . json_encode ($ message ));
411406 }
412407
413408 if ($ response ->getType () === ResponseType::RUNTIME_ERROR ) {
414- throw new ConnectionException ('Runtime error: ' . $ response ->getData ()[0 ]. ', jsonQuery: ' . json_encode ($ message ));
409+ throw new ConnectionException ('Runtime error: ' . $ response ->getData ()[0 ] . ', jsonQuery: ' . json_encode ($ message ));
415410 }
416411 }
417412}
0 commit comments