diff --git a/src/protocol/AcknowledgePacket.php b/src/protocol/AcknowledgePacket.php index 6a18733..587f6db 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/protocol/Datagram.php b/src/protocol/Datagram.php index e93e299..c7c69ea 100644 --- a/src/protocol/Datagram.php +++ b/src/protocol/Datagram.php @@ -50,7 +50,7 @@ protected function encodePayload(PacketSerializer $out) : void{ /** * @return int */ - public function length(){ + public function length(): int{ $length = self::HEADER_SIZE; foreach($this->packets as $packet){ $length += $packet->getTotalLength(); diff --git a/src/protocol/OfflineMessage.php b/src/protocol/OfflineMessage.php index d157d0f..ea5e88e 100644 --- a/src/protocol/OfflineMessage.php +++ b/src/protocol/OfflineMessage.php @@ -32,14 +32,14 @@ abstract class OfflineMessage extends Packet{ * @return void * @throws BinaryDataException */ - protected function readMagic(BinaryStream $in){ + protected function readMagic(BinaryStream $in): void{ $this->magic = $in->get(16); } /** * @return void */ - protected function writeMagic(BinaryStream $out){ + protected function writeMagic(BinaryStream $out): void{ $out->put($this->magic); } diff --git a/src/protocol/Packet.php b/src/protocol/Packet.php index 27e24c1..884919c 100644 --- a/src/protocol/Packet.php +++ b/src/protocol/Packet.php @@ -20,7 +20,7 @@ abstract class Packet{ /** @var int */ - public static $ID = -1; + public static int $ID = -1; public function encode(PacketSerializer $out) : void{ $this->encodeHeader($out); diff --git a/src/server/Server.php b/src/server/Server.php index 95eb9fd..e1d2121 100644 --- a/src/server/Server.php +++ b/src/server/Server.php @@ -397,7 +397,7 @@ public function openSession(ServerSession $session) : void{ private function checkSessions() : void{ if(count($this->sessions) > 4096){ - foreach($this->sessions as $sessionId => $session){ + foreach($this->sessions as $session){ if($session->isTemporary()){ $this->removeSessionInternal($session); if(count($this->sessions) <= 4096){ diff --git a/src/server/ServerSocket.php b/src/server/ServerSocket.php index 0cd7852..a4dce99 100644 --- a/src/server/ServerSocket.php +++ b/src/server/ServerSocket.php @@ -59,9 +59,10 @@ public function disableBroadcast() : bool{ } /** - * @param string $source reference parameter - * @param int $port reference parameter + * @param string|null $source reference parameter + * @param int|null $port reference parameter * + * @return string|null * @throws SocketException */ public function readPacket(?string &$source, ?int &$port) : ?string{ 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;