From 319664e24ea9c38ed12390ea55e186fdf92fc103 Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:37:07 +0300 Subject: [PATCH 1/8] fix CS Unused local variable 'sessionId'. The value of the variable is not used anywhere. --- src/server/Server.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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){ From 98e0b0b33aa49ba6bac22d0b91c4b6a4197156bf Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:38:45 +0300 Subject: [PATCH 2/8] fix PHPDoc Argument type does not match the declared --- src/server/ServerSocket.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server/ServerSocket.php b/src/server/ServerSocket.php index 0cd7852..2a5e7e4 100644 --- a/src/server/ServerSocket.php +++ b/src/server/ServerSocket.php @@ -59,10 +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 * - * @throws SocketException + * @return string|null */ public function readPacket(?string &$source, ?int &$port) : ?string{ $buffer = ""; From 4d4f61a086a53cd43d7939526be1ac75148a8d5a Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:43:19 +0300 Subject: [PATCH 3/8] fix CS 'if' statement with common parts --- src/protocol/AcknowledgePacket.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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; } } From c2c4d08dcd30fa065e18a2321755c6be99c20413 Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:44:44 +0300 Subject: [PATCH 4/8] fix CS Add 'int' as the function's return type --- src/protocol/Datagram.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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(); From 4ae8a271e32edec55c87892401156a82da770182 Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:46:12 +0300 Subject: [PATCH 5/8] fix CS Missing 'void' return type --- src/protocol/OfflineMessage.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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); } From 660e60484d04e2e5baff9cc3873fa43fb0e2cc31 Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:47:07 +0300 Subject: [PATCH 6/8] fix CS missing 'int' type --- src/protocol/Packet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From f2cb075fb6c1e89b8dbc267183341cd3feab35a4 Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:52:01 +0300 Subject: [PATCH 7/8] Updated for PHP 8.* --- src/utils/ExceptionTraceCleaner.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) 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; From 6c152c021c8d9db5d9b13d34472ac2ba88b112f4 Mon Sep 17 00:00:00 2001 From: ismail <74091824+ismaileke@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:53:42 +0300 Subject: [PATCH 8/8] zzz... --- src/server/ServerSocket.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/ServerSocket.php b/src/server/ServerSocket.php index 2a5e7e4..a4dce99 100644 --- a/src/server/ServerSocket.php +++ b/src/server/ServerSocket.php @@ -63,6 +63,7 @@ public function disableBroadcast() : bool{ * @param int|null $port reference parameter * * @return string|null + * @throws SocketException */ public function readPacket(?string &$source, ?int &$port) : ?string{ $buffer = "";