From b974f8c8921dc80b730c333e1a4e53407b1f37cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gamez?= <jerome@gamez.name>
Date: Thu, 23 May 2024 02:01:24 +0200
Subject: [PATCH] Replace `elseif`s with early returns

---
 spec/generate.php  |  52 +++++--
 src/Connection.php | 332 ++++++++++++++++++++++++++++++++++-----------
 2 files changed, 292 insertions(+), 92 deletions(-)

diff --git a/spec/generate.php b/spec/generate.php
index 38a5444..4a6b309 100644
--- a/spec/generate.php
+++ b/spec/generate.php
@@ -355,16 +355,20 @@ function amqpTypeToLength($type, $e)
 $connectionContent .= "     */\n";
 $connectionContent .= "    private function onFrameReceived(AbstractFrame \$frame)\n";
 $connectionContent .= "    {\n";
-$connectionContent .= "        if (\$frame instanceof MethodFrame) {\n";
-$connectionContent .= "            if (\$frame instanceof MethodConnectionCloseFrame) {\n";
-$connectionContent .= "                \$this->disconnect(Constants::STATUS_CONNECTION_FORCED, \"Connection closed by server: ({\$frame->replyCode}) \" . \$frame->replyText);\n";
-$connectionContent .= "                throw new ClientException('Connection closed by server: ' . \$frame->replyText, \$frame->replyCode);\n";
-$connectionContent .= "            }\n";
-$connectionContent .= "        } elseif (\$frame instanceof ContentHeaderFrame) {\n";
+$connectionContent .= "        if (\$frame instanceof MethodConnectionCloseFrame) {\n";
+$connectionContent .= "            \$this->disconnect(Constants::STATUS_CONNECTION_FORCED, \"Connection closed by server: ({\$frame->replyCode}) \" . \$frame->replyText);\n";
+$connectionContent .= "            throw new ClientException('Connection closed by server: ' . \$frame->replyText, \$frame->replyCode);\n";
+$connectionContent .= "        }\n";
+$connectionContent .= "\n";
+$connectionContent .= "        if (\$frame instanceof ContentHeaderFrame) {\n";
 $connectionContent .= "            \$this->disconnect(Constants::STATUS_UNEXPECTED_FRAME, 'Got header frame on connection channel (#0).');\n";
-$connectionContent .= "        } elseif (\$frame instanceof ContentBodyFrame) {\n";
+$connectionContent .= "        }\n";
+$connectionContent .= "\n";
+$connectionContent .= "        if (\$frame instanceof ContentBodyFrame) {\n";
 $connectionContent .= "            \$this->disconnect(Constants::STATUS_UNEXPECTED_FRAME, 'Got body frame on connection channel (#0).');\n";
-$connectionContent .= "        } elseif (\$frame instanceof HeartbeatFrame) {\n";
+$connectionContent .= "        }\n";
+$connectionContent .= "\n";
+$connectionContent .= "        if (\$frame instanceof HeartbeatFrame) {\n";
 $connectionContent .= "            return;\n";
 $connectionContent .= "        }\n";
 $connectionContent .= "\n";
@@ -396,10 +400,14 @@ function amqpTypeToLength($type, $e)
 $connectionContent .= "            'filter' => function (AbstractFrame \$frame) use (\$channel): bool {\n";
 $connectionContent .= "                if (\$frame instanceof Protocol\\ContentHeaderFrame && \$frame->channel === \$channel) {\n";
 $connectionContent .= "                    return true;\n";
-$connectionContent .= "    } elseif (\$frame instanceof Protocol\\MethodChannelCloseFrame && \$frame->channel === \$channel) {\n";
+$connectionContent .= "                }\n";
+$connectionContent .= "\n";
+$connectionContent .= "                if (\$frame instanceof Protocol\\MethodChannelCloseFrame && \$frame->channel === \$channel) {\n";
 $connectionContent .= "                    \$this->channelCloseOk(\$channel);\n";
 $connectionContent .= "                    throw new ClientException(\$frame->replyText, \$frame->replyCode);\n";
-$connectionContent .= "                } elseif (\$frame instanceof Protocol\\MethodConnectionCloseFrame) {\n";
+$connectionContent .= "                }\n";
+$connectionContent .= "\n";
+$connectionContent .= "                if (\$frame instanceof Protocol\\MethodConnectionCloseFrame) {\n";
 $connectionContent .= "                    \$this->connectionCloseOk();\n";
 $connectionContent .= "                    throw new ClientException(\$frame->replyText, \$frame->replyCode);\n";
 $connectionContent .= "                }\n";
@@ -419,10 +427,14 @@ function amqpTypeToLength($type, $e)
 $connectionContent .= "            'filter' => function (AbstractFrame \$frame) use (\$channel): bool {\n";
 $connectionContent .= "                if (\$frame instanceof Protocol\\ContentBodyFrame && \$frame->channel === \$channel) {\n";
 $connectionContent .= "                    return true;\n";
-$connectionContent .= "                } elseif (\$frame instanceof Protocol\\MethodChannelCloseFrame && \$frame->channel === \$channel) {\n";
+$connectionContent .= "                }\n";
+$connectionContent .= "\n";
+$connectionContent .= "                if (\$frame instanceof Protocol\\MethodChannelCloseFrame && \$frame->channel === \$channel) {\n";
 $connectionContent .= "                    \$this->channelCloseOk(\$channel);\n";
 $connectionContent .= "                    throw new ClientException(\$frame->replyText, \$frame->replyCode);\n";
-$connectionContent .= "                } elseif (\$frame instanceof Protocol\\MethodConnectionCloseFrame) {\n";
+$connectionContent .= "                }\n";
+$connectionContent .= "\n";
+$connectionContent .= "                if (\$frame instanceof Protocol\\MethodConnectionCloseFrame) {\n";
 $connectionContent .= "                    \$this->connectionCloseOk();\n";
 $connectionContent .= "                    throw new ClientException(\$frame->replyText, \$frame->replyCode);\n";
 $connectionContent .= "                }\n";
@@ -882,19 +894,29 @@ function amqpTypeToLength($type, $e)
             $connectionContent .= "            'filter' => function (Protocol\\AbstractFrame \$frame)" . ($class->id !== 10 ? " use (\$channel)" : "") . ": bool {\n";
             $connectionContent .= "                if (\$frame instanceof Protocol\\{$className}" . ($class->id !== 10 ? " && \$frame->channel === \$channel" : "") . ") {\n";
             $connectionContent .= "                    return true;\n";
+            $connectionContent .= "                }\n";
+            $connectionContent .= "\n";
+
             if ($class->id === 60 && $method->id === 71) {
-                $connectionContent .=     "            } elseif (\$frame instanceof Protocol\\" . str_replace("GetOk", "GetEmpty", $className) . ($class->id !== 10 ? " && \$frame->channel === \$channel" : "") . ") {\n";
+                $connectionContent .= "                if (\$frame instanceof Protocol\\" . str_replace("GetOk", "GetEmpty", $className) . ($class->id !== 10 ? " && \$frame->channel === \$channel" : "") . ") {\n";
                 $connectionContent .= "                    return true;\n";
+                $connectionContent .= "                }\n";
+                $connectionContent .= "\n";
             }
+
             if ($class->id !== 10) {
-                $connectionContent .= "                } elseif (\$frame instanceof Protocol\\MethodChannelCloseFrame && \$frame->channel === \$channel) {\n";
+                $connectionContent .= "                if (\$frame instanceof Protocol\\MethodChannelCloseFrame && \$frame->channel === \$channel) {\n";
                 $connectionContent .= "                    \$this->channelCloseOk(\$channel);\n";
                 $connectionContent .= "                    throw new ClientException(\$frame->replyText, \$frame->replyCode);\n";
+                $connectionContent .= "                }\n";
+                $connectionContent .= "\n";
             }
-            $connectionContent .= "                } elseif (\$frame instanceof Protocol\\MethodConnectionCloseFrame) {\n";
+
+            $connectionContent .= "                if (\$frame instanceof Protocol\\MethodConnectionCloseFrame) {\n";
             $connectionContent .= "                    \$this->connectionCloseOk();\n";
             $connectionContent .= "                    throw new ClientException(\$frame->replyText, \$frame->replyCode);\n";
             $connectionContent .= "                }\n";
+            $connectionContent .= "\n";
             $connectionContent .= "                return false;\n";
             $connectionContent .= "          },\n";
             $connectionContent .= "          'promise' => \$deferred,\n";
diff --git a/src/Connection.php b/src/Connection.php
index bc039ba..ed5a9c7 100644
--- a/src/Connection.php
+++ b/src/Connection.php
@@ -102,16 +102,20 @@ public function disconnect(int $code, string $reason)
      */
     private function onFrameReceived(AbstractFrame $frame)
     {
-        if ($frame instanceof MethodFrame) {
-            if ($frame instanceof MethodConnectionCloseFrame) {
-                $this->disconnect(Constants::STATUS_CONNECTION_FORCED, "Connection closed by server: ({$frame->replyCode}) " . $frame->replyText);
-                throw new ClientException('Connection closed by server: ' . $frame->replyText, $frame->replyCode);
-            }
-        } elseif ($frame instanceof ContentHeaderFrame) {
+        if ($frame instanceof MethodConnectionCloseFrame) {
+            $this->disconnect(Constants::STATUS_CONNECTION_FORCED, "Connection closed by server: ({$frame->replyCode}) " . $frame->replyText);
+            throw new ClientException('Connection closed by server: ' . $frame->replyText, $frame->replyCode);
+        }
+
+        if ($frame instanceof ContentHeaderFrame) {
             $this->disconnect(Constants::STATUS_UNEXPECTED_FRAME, 'Got header frame on connection channel (#0).');
-        } elseif ($frame instanceof ContentBodyFrame) {
+        }
+
+        if ($frame instanceof ContentBodyFrame) {
             $this->disconnect(Constants::STATUS_UNEXPECTED_FRAME, 'Got body frame on connection channel (#0).');
-        } elseif ($frame instanceof HeartbeatFrame) {
+        }
+
+        if ($frame instanceof HeartbeatFrame) {
             return;
         }
 
@@ -143,10 +147,14 @@ public function awaitContentHeader(int $channel): ContentHeaderFrame
             'filter' => function (AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\ContentHeaderFrame && $frame->channel === $channel) {
                     return true;
-    } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
@@ -166,10 +174,14 @@ public function awaitContentBody(int $channel): ContentBodyFrame
             'filter' => function (AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\ContentBodyFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
@@ -188,10 +200,13 @@ public function awaitConnectionStart(): Protocol\MethodConnectionStartFrame
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionStartFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -224,10 +239,13 @@ public function awaitConnectionSecure(): Protocol\MethodConnectionSecureFrame
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionSecureFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -256,10 +274,13 @@ public function awaitConnectionTune(): Protocol\MethodConnectionTuneFrame
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionTuneFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -306,10 +327,13 @@ public function awaitConnectionOpenOk(): Protocol\MethodConnectionOpenOkFrame
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionOpenOkFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -341,10 +365,13 @@ public function awaitConnectionClose(): Protocol\MethodConnectionCloseFrame
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -372,10 +399,13 @@ public function awaitConnectionCloseOk(): Protocol\MethodConnectionCloseOkFrame
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionCloseOkFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -390,10 +420,13 @@ public function awaitConnectionBlocked(): Protocol\MethodConnectionBlockedFrame
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionBlockedFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -408,10 +441,13 @@ public function awaitConnectionUnblocked(): Protocol\MethodConnectionUnblockedFr
             'filter' => function (Protocol\AbstractFrame $frame): bool {
                 if ($frame instanceof Protocol\MethodConnectionUnblockedFrame) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -440,13 +476,18 @@ public function awaitChannelOpenOk(int $channel): Protocol\MethodChannelOpenOkFr
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodChannelOpenOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -475,13 +516,18 @@ public function awaitChannelFlow(int $channel): Protocol\MethodChannelFlowFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodChannelFlowFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -510,13 +556,18 @@ public function awaitChannelFlowOk(int $channel): Protocol\MethodChannelFlowOkFr
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodChannelFlowOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -548,13 +599,18 @@ public function awaitChannelClose(int $channel): Protocol\MethodChannelCloseFram
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -582,13 +638,18 @@ public function awaitChannelCloseOk(int $channel): Protocol\MethodChannelCloseOk
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodChannelCloseOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -618,13 +679,18 @@ public function awaitAccessRequestOk(int $channel): Protocol\MethodAccessRequest
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodAccessRequestOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -661,13 +727,18 @@ public function awaitExchangeDeclareOk(int $channel): Protocol\MethodExchangeDec
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodExchangeDeclareOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -701,13 +772,18 @@ public function awaitExchangeDeleteOk(int $channel): Protocol\MethodExchangeDele
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodExchangeDeleteOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -745,13 +821,18 @@ public function awaitExchangeBindOk(int $channel): Protocol\MethodExchangeBindOk
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodExchangeBindOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -789,13 +870,18 @@ public function awaitExchangeUnbindOk(int $channel): Protocol\MethodExchangeUnbi
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodExchangeUnbindOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -831,13 +917,18 @@ public function awaitQueueDeclareOk(int $channel): Protocol\MethodQueueDeclareOk
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodQueueDeclareOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -875,13 +966,18 @@ public function awaitQueueBindOk(int $channel): Protocol\MethodQueueBindOkFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodQueueBindOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -915,13 +1011,18 @@ public function awaitQueuePurgeOk(int $channel): Protocol\MethodQueuePurgeOkFram
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodQueuePurgeOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -955,13 +1056,18 @@ public function awaitQueueDeleteOk(int $channel): Protocol\MethodQueueDeleteOkFr
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodQueueDeleteOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -995,13 +1101,18 @@ public function awaitQueueUnbindOk(int $channel): Protocol\MethodQueueUnbindOkFr
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodQueueUnbindOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1032,13 +1143,18 @@ public function awaitQosOk(int $channel): Protocol\MethodBasicQosOkFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicQosOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1075,13 +1191,18 @@ public function awaitConsumeOk(int $channel): Protocol\MethodBasicConsumeOkFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicConsumeOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1114,13 +1235,18 @@ public function awaitCancelOk(int $channel): Protocol\MethodBasicCancelOkFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicCancelOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1321,13 +1447,18 @@ public function awaitReturn(int $channel): Protocol\MethodBasicReturnFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicReturnFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1342,13 +1473,18 @@ public function awaitDeliver(int $channel): Protocol\MethodBasicDeliverFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicDeliverFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1379,15 +1515,22 @@ public function awaitGetOk(int $channel): Protocol\MethodBasicGetOkFrame|Protoco
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicGetOkFrame && $frame->channel === $channel) {
                     return true;
-            } elseif ($frame instanceof Protocol\MethodBasicGetEmptyFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodBasicGetEmptyFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1417,13 +1560,18 @@ public function awaitAck(int $channel): Protocol\MethodBasicAckFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicAckFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1481,13 +1629,18 @@ public function awaitRecoverOk(int $channel): Protocol\MethodBasicRecoverOkFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicRecoverOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1517,13 +1670,18 @@ public function awaitNack(int $channel): Protocol\MethodBasicNackFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodBasicNackFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1551,13 +1709,18 @@ public function awaitTxSelectOk(int $channel): Protocol\MethodTxSelectOkFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodTxSelectOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1585,13 +1748,18 @@ public function awaitTxCommitOk(int $channel): Protocol\MethodTxCommitOkFrame
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodTxCommitOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1619,13 +1787,18 @@ public function awaitTxRollbackOk(int $channel): Protocol\MethodTxRollbackOkFram
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodTxRollbackOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,
@@ -1657,13 +1830,18 @@ public function awaitConfirmSelectOk(int $channel): Protocol\MethodConfirmSelect
             'filter' => function (Protocol\AbstractFrame $frame) use ($channel): bool {
                 if ($frame instanceof Protocol\MethodConfirmSelectOkFrame && $frame->channel === $channel) {
                     return true;
-                } elseif ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
+                }
+
+                if ($frame instanceof Protocol\MethodChannelCloseFrame && $frame->channel === $channel) {
                     $this->channelCloseOk($channel);
                     throw new ClientException($frame->replyText, $frame->replyCode);
-                } elseif ($frame instanceof Protocol\MethodConnectionCloseFrame) {
+                }
+
+                if ($frame instanceof Protocol\MethodConnectionCloseFrame) {
                     $this->connectionCloseOk();
                     throw new ClientException($frame->replyText, $frame->replyCode);
                 }
+
                 return false;
           },
           'promise' => $deferred,