Refactoring: remove Connection::sendWithResponse

This commit is contained in:
2021-01-25 01:25:52 +03:00
parent 33ef674e58
commit 66b5b77bef
3 changed files with 7 additions and 9 deletions

View File

@ -89,7 +89,7 @@ abstract class Connection
$body = json_encode($this->features, JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT); $body = json_encode($this->features, JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT);
$size = pack('N', \strlen($body)); $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; return $response;
} }
protected function sendWithResponse(string $buffer): Response protected function response(): Response
{ {
return $this return $this->receive(1) ?? throw UnexpectedResponse::null();
->send($buffer)
->receive(1) ?? throw UnexpectedResponse::null();
} }
private function socket(): Socket private function socket(): Socket

View File

@ -15,7 +15,7 @@ final class Consumer extends Connection
{ {
$buffer = sprintf('SUB %s %s', $topic, $channel).PHP_EOL; $buffer = sprintf('SUB %s %s', $topic, $channel).PHP_EOL;
$this->sendWithResponse($buffer)->okOrFail(); $this->send($buffer)->response()->okOrFail();
} }
/** /**

View File

@ -21,7 +21,7 @@ final class Producer extends Connection
$buffer = 'PUB '.$topic.PHP_EOL.$size.$body; $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; $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; $buffer = sprintf('DPUB %s %s', $topic, $deferTime).PHP_EOL.$size.$body;
$this->sendWithResponse($buffer)->okOrFail(); $this->send($buffer)->response()->okOrFail();
} }
} }