From 66b5b77befd9a864076fede78c1bd7a4b727c915 Mon Sep 17 00:00:00 2001 From: Konstantin Grachev Date: Mon, 25 Jan 2021 01:25:52 +0300 Subject: [PATCH] Refactoring: remove Connection::sendWithResponse --- src/Connection.php | 8 +++----- src/Consumer.php | 2 +- src/Producer.php | 6 +++--- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index f53764d..28a5f52 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -89,7 +89,7 @@ abstract class Connection $body = json_encode($this->features, JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT); $size = pack('N', \strlen($body)); - $this->sendWithResponse('IDENTIFY '.PHP_EOL.$size.$body)->okOrFail(); + $this->send('IDENTIFY '.PHP_EOL.$size.$body)->response()->okOrFail(); }); } @@ -214,11 +214,9 @@ abstract class Connection return $response; } - protected function sendWithResponse(string $buffer): Response + protected function response(): Response { - return $this - ->send($buffer) - ->receive(1) ?? throw UnexpectedResponse::null(); + return $this->receive(1) ?? throw UnexpectedResponse::null(); } private function socket(): Socket diff --git a/src/Consumer.php b/src/Consumer.php index 495bb55..8488045 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -15,7 +15,7 @@ final class Consumer extends Connection { $buffer = sprintf('SUB %s %s', $topic, $channel).PHP_EOL; - $this->sendWithResponse($buffer)->okOrFail(); + $this->send($buffer)->response()->okOrFail(); } /** diff --git a/src/Producer.php b/src/Producer.php index 3740938..fd74bb5 100644 --- a/src/Producer.php +++ b/src/Producer.php @@ -21,7 +21,7 @@ final class Producer extends Connection $buffer = 'PUB '.$topic.PHP_EOL.$size.$body; - $this->sendWithResponse($buffer)->okOrFail(); + $this->send($buffer)->response()->okOrFail(); } /** @@ -41,7 +41,7 @@ final class Producer extends Connection $buffer = 'MPUB '.$topic.PHP_EOL.$size.$num.$mb; - $this->sendWithResponse($buffer)->okOrFail(); + $this->send($buffer)->response()->okOrFail(); } /** @@ -53,6 +53,6 @@ final class Producer extends Connection $buffer = sprintf('DPUB %s %s', $topic, $deferTime).PHP_EOL.$size.$body; - $this->sendWithResponse($buffer)->okOrFail(); + $this->send($buffer)->response()->okOrFail(); } }