From adca63d1fd428c7c0039fb6197e6f9785da30914 Mon Sep 17 00:00:00 2001 From: ismaileke Date: Tue, 25 Jun 2024 14:39:12 +0300 Subject: [PATCH] Clean code --- src/protocol/AcknowledgePacket.php | 3 +-- src/utils/ExceptionTraceCleaner.php | 10 +++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/protocol/AcknowledgePacket.php b/src/protocol/AcknowledgePacket.php index 6a18733..54c85ab 100644 --- a/src/protocol/AcknowledgePacket.php +++ b/src/protocol/AcknowledgePacket.php @@ -49,13 +49,12 @@ protected function encodePayload(PacketSerializer $out) : void{ if($start === $last){ $payload .= chr(self::RECORD_TYPE_SINGLE); $payload .= Binary::writeLTriad($start); - $start = $last = $current; }else{ $payload .= chr(self::RECORD_TYPE_RANGE); $payload .= Binary::writeLTriad($start); $payload .= Binary::writeLTriad($last); - $start = $last = $current; } + $start = $last = $current; ++$records; } } diff --git a/src/utils/ExceptionTraceCleaner.php b/src/utils/ExceptionTraceCleaner.php index 8e71b3a..06ce876 100644 --- a/src/utils/ExceptionTraceCleaner.php +++ b/src/utils/ExceptionTraceCleaner.php @@ -53,16 +53,12 @@ public function getTrace(int $start = 0, ?array $trace = null) : array{ for($i = $start; isset($trace[$i]); ++$i, ++$j){ $params = ""; if(isset($trace[$i]["args"]) or isset($trace[$i]["params"])){ - if(isset($trace[$i]["args"])){ - $args = $trace[$i]["args"]; - }else{ - $args = $trace[$i]["params"]; - } - foreach($args as $name => $value){ + $args = $trace[$i]["args"] ?? $trace[$i]["params"]; + foreach($args as $value){ $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", "; } } - $messages[] = "#$j " . (isset($trace[$i]["file"]) ? $this->cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")"; + $messages[] = "#$j " . (isset($trace[$i]["file"]) ? $this->cleanPath($trace[$i]["file"]) : "") . "(" . ($trace[$i]["line"] ?? "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")"; } return $messages;