diff --git a/src/Bunny/Async/Client.php b/src/Bunny/Async/Client.php index af4b971..f0929a8 100644 --- a/src/Bunny/Async/Client.php +++ b/src/Bunny/Async/Client.php @@ -93,7 +93,7 @@ public function __destruct() /** * Initializes instance. */ - protected function init() + protected function init(): void { parent::init(); $this->flushWriteBufferPromise = null; @@ -106,7 +106,7 @@ protected function init() * * @param float $maxSeconds */ - public function run($maxSeconds = null) + public function run($maxSeconds = null): void { if ($maxSeconds !== null) { $this->stopTimer = $this->eventLoop->addTimer($maxSeconds, function () { @@ -120,7 +120,7 @@ public function run($maxSeconds = null) /** * Calls {@link eventLoop}'s stop() method. */ - public function stop() + public function stop(): void { if ($this->stopTimer) { $this->eventLoop->cancelTimer($this->stopTimer); @@ -143,10 +143,8 @@ protected function feedReadBuffer() * * - Calls {@link eventLoops}'s addWriteStream() with client's stream. * - Consecutive calls will return the same instance of promise. - * - * @return Promise\PromiseInterface */ - protected function flushWriteBuffer() + protected function flushWriteBuffer(): Promise\PromiseInterface { if ($this->flushWriteBufferPromise) { return $this->flushWriteBufferPromise; @@ -179,10 +177,8 @@ protected function flushWriteBuffer() * Connects to AMQP server. * * Calling connect() multiple times will result in error. - * - * @return Promise\PromiseInterface */ - public function connect() + public function connect(): Promise\PromiseInterface { if ($this->state !== ClientStateEnum::NOT_CONNECTED) { return Promise\reject(new ClientException("Client already connected/connecting.")); @@ -233,9 +229,8 @@ public function connect() * * @param int $replyCode * @param string $replyText - * @return Promise\PromiseInterface */ - public function disconnect($replyCode = 0, $replyText = "") + public function disconnect($replyCode = 0, $replyText = ""): Promise\PromiseInterface { if ($this->state === ClientStateEnum::DISCONNECTING) { return $this->disconnectPromise; @@ -289,7 +284,7 @@ public function disconnect($replyCode = 0, $replyText = "") * * @param callable $callback */ - public function addAwaitCallback(callable $callback) + public function addAwaitCallback(callable $callback): void { $this->awaitCallbacks[] = $callback; } @@ -297,7 +292,7 @@ public function addAwaitCallback(callable $callback) /** * {@link eventLoop}'s read stream callback notifying client that data from server arrived. */ - public function onDataAvailable() + public function onDataAvailable(): void { $this->read(); @@ -327,7 +322,7 @@ public function onDataAvailable() /** * Callback when heartbeat timer timed out. */ - public function onHeartbeat() + public function onHeartbeat(): void { $now = microtime(true); $nextHeartbeat = ($this->lastWrite ?: $now) + $this->options["heartbeat"]; @@ -345,5 +340,4 @@ public function onHeartbeat() $this->heartbeatTimer = $this->eventLoop->addTimer($nextHeartbeat - $now, [$this, "onHeartbeat"]); } } - } diff --git a/src/Bunny/Channel.php b/src/Bunny/Channel.php index 8dcaddf..5addc91 100644 --- a/src/Bunny/Channel.php +++ b/src/Bunny/Channel.php @@ -111,30 +111,24 @@ public function __construct(AbstractClient $client, $channelId) /** * Returns underlying client instance. - * - * @return AbstractClient */ - public function getClient() + public function getClient(): AbstractClient { return $this->client; } /** * Returns channel id. - * - * @return int */ - public function getChannelId() + public function getChannelId(): int { return $this->channelId; } /** * Returns the channel mode. - * - * @return int */ - public function getMode() + public function getMode(): int { return $this->mode; } @@ -143,9 +137,8 @@ public function getMode() * Listener is called whenever 'basic.return' frame is received with arguments (Message $returnedMessage, MethodBasicReturnFrame $frame) * * @param callable $callback - * @return $this */ - public function addReturnListener(callable $callback) + public function addReturnListener(callable $callback): self { $this->removeReturnListener($callback); // remove if previously added to prevent calling multiple times $this->returnCallbacks[] = $callback; @@ -156,9 +149,8 @@ public function addReturnListener(callable $callback) * Removes registered return listener. If the callback is not registered, this is noop. * * @param callable $callback - * @return $this */ - public function removeReturnListener(callable $callback) + public function removeReturnListener(callable $callback): self { foreach ($this->returnCallbacks as $k => $v) { if ($v === $callback) { @@ -173,9 +165,8 @@ public function removeReturnListener(callable $callback) * Listener is called whenever 'basic.ack' or 'basic.nack' is received. * * @param callable $callback - * @return $this */ - public function addAckListener(callable $callback) + public function addAckListener(callable $callback): self { if ($this->mode !== ChannelModeEnum::CONFIRM) { throw new ChannelException("Ack/nack listener can be added when channel in confirm mode."); @@ -190,9 +181,8 @@ public function addAckListener(callable $callback) * Removes registered ack/nack listener. If the callback is not registered, this is noop. * * @param callable $callback - * @return $this */ - public function removeAckListener(callable $callback) + public function removeAckListener(callable $callback): self { if ($this->mode !== ChannelModeEnum::CONFIRM) { throw new ChannelException("Ack/nack listener can be removed when channel in confirm mode."); @@ -214,9 +204,8 @@ public function removeAckListener(callable $callback) * * @param int $replyCode * @param string $replyText - * @return PromiseInterface */ - public function close($replyCode = 0, $replyText = "") + public function close($replyCode = 0, $replyText = ""): PromiseInterface { if ($this->state === ChannelStateEnum::CLOSED) { throw new ChannelException("Trying to close already closed channel #{$this->channelId}."); @@ -283,7 +272,7 @@ public function consume(callable $callback, $queue = "", $consumerTag = "", $noL * @param bool $nowait * @param array $arguments */ - public function run(callable $callback, $queue = "", $consumerTag = "", $noLocal = false, $noAck = false, $exclusive = false, $nowait = false, $arguments = []) + public function run(callable $callback, $queue = "", $consumerTag = "", $noLocal = false, $noAck = false, $exclusive = false, $nowait = false, $arguments = []): void { $response = $this->consume($callback, $queue, $consumerTag, $noLocal, $noAck, $exclusive, $nowait, $arguments); @@ -558,7 +547,7 @@ private function enterConfirmMode(callable $callback = null) * * @param AbstractFrame $frame */ - public function onFrameReceived(AbstractFrame $frame) + public function onFrameReceived(AbstractFrame $frame): void { if ($this->state === ChannelStateEnum::ERROR) { throw new ChannelException("Channel in error state."); @@ -704,7 +693,7 @@ public function onFrameReceived(AbstractFrame $frame) /** * Callback after content body has been completely received. */ - protected function onBodyComplete() + protected function onBodyComplete(): void { if ($this->returnFrame) { $content = $this->bodyBuffer->consume($this->bodyBuffer->getLength()); diff --git a/src/Bunny/Client.php b/src/Bunny/Client.php index bde19ab..bc60865 100644 --- a/src/Bunny/Client.php +++ b/src/Bunny/Client.php @@ -67,10 +67,8 @@ public function __destruct() /** * Reads data from stream to {@link readBuffer}. - * - * @return boolean */ - protected function feedReadBuffer() + protected function feedReadBuffer(): bool { $this->read(); return true; @@ -78,10 +76,8 @@ protected function feedReadBuffer() /** * Writes all data from {@link writeBuffer} to stream. - * - * @return boolean */ - protected function flushWriteBuffer() + protected function flushWriteBuffer(): bool { while (!$this->writeBuffer->isEmpty()) { $this->write(); @@ -93,9 +89,8 @@ protected function flushWriteBuffer() * Synchronously connects to AMQP server. * * @throws \Exception - * @return self */ - public function connect() + public function connect(): self { if ($this->state !== ClientStateEnum::NOT_CONNECTED) { throw new ClientException("Client already connected/connecting."); @@ -130,9 +125,9 @@ public function connect() * * @param int $replyCode * @param string $replyText - * @return Promise\PromiseInterface + * @return */ - public function disconnect($replyCode = 0, $replyText = "") + public function disconnect($replyCode = 0, $replyText = ""): Promise\PromiseInterface { if ($this->state === ClientStateEnum::DISCONNECTING) { return $this->disconnectPromise; @@ -169,7 +164,7 @@ public function disconnect($replyCode = 0, $replyText = "") * * @param float $maxSeconds */ - public function run($maxSeconds = null) + public function run($maxSeconds = null): void { if (!$this->isConnected()) { throw new ClientException("Client has to be connected."); @@ -263,7 +258,7 @@ public function run($maxSeconds = null) /** * Stops client's event loop. */ - public function stop() + public function stop(): void { $this->running = false; }