walkor 1 năm trước cách đây
mục cha
commit
124305dae4

+ 2 - 6
src/Connection/AsyncUdpConnection.php

@@ -108,9 +108,7 @@ class AsyncUdpConnection extends UdpConnection
 
         if ($this->onMessage) {
             if ($this->protocol) {
-                /** @var ProtocolInterface $parser */
-                $parser = $this->protocol;
-                $recvBuffer = $parser::decode($recvBuffer, $this);
+                $recvBuffer = $this->protocol::decode($recvBuffer, $this);
             }
             ++ConnectionInterface::$statistics['total_request'];
             try {
@@ -157,9 +155,7 @@ class AsyncUdpConnection extends UdpConnection
     public function send(mixed $sendBuffer, bool $raw = false): bool|null
     {
         if (false === $raw && $this->protocol) {
-            /** @var ProtocolInterface $parser */
-            $parser = $this->protocol;
-            $sendBuffer = $parser::encode($sendBuffer, $this);
+            $sendBuffer = $this->protocol::encode($sendBuffer, $this);
             if ($sendBuffer === '') {
                 return null;
             }

+ 3 - 7
src/Connection/TcpConnection.php

@@ -270,7 +270,7 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
     /**
      * Cache.
      *
-     * @var bool.
+     * @var bool
      */
     protected static bool $enableCache = true;
 
@@ -409,10 +409,8 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
 
         // Try to call protocol::encode($sendBuffer) before sending.
         if (false === $raw && $this->protocol !== null) {
-            /** @var ProtocolInterface $parser */
-            $parser = $this->protocol;
             try {
-                $sendBuffer = $parser::encode($sendBuffer, $this);
+                $sendBuffer = $this->protocol::encode($sendBuffer, $this);
             } catch(Throwable $e) {
                 $this->error($e);
             }
@@ -730,9 +728,7 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
                 $this->currentPackageLength = 0;
                 try {
                     // Decode request buffer before Emitting onMessage callback.
-                    /** @var ProtocolInterface $parser */
-                    $parser = $this->protocol;
-                    $request = $parser::decode($oneRequestBuffer, $this);
+                    $request = $this->protocol::decode($oneRequestBuffer, $this);
                     if (static::$enableCache && (!is_object($request) || $request instanceof Request) && $one && !isset($oneRequestBuffer[static::MAX_CACHE_STRING_LENGTH])) {
                         ($this->onMessage)($this, $request);
                         if ($request instanceof Request) {

+ 1 - 3
src/Connection/UdpConnection.php

@@ -65,9 +65,7 @@ class UdpConnection extends ConnectionInterface implements JsonSerializable
     public function send(mixed $sendBuffer, bool $raw = false): bool|null
     {
         if (false === $raw && $this->protocol) {
-            /** @var ProtocolInterface $parser */
-            $parser = $this->protocol;
-            $sendBuffer = $parser::encode($sendBuffer, $this);
+            $sendBuffer = $this->protocol::encode($sendBuffer, $this);
             if ($sendBuffer === '') {
                 return null;
             }

+ 1 - 1
src/Events/Swoole.php

@@ -39,7 +39,7 @@ final class Swoole implements EventInterface
     /**
      * All listeners for write event.
      *
-     * @var array<int, resource>
+     * @var array<int, array>
      */
     private array $writeEvents = [];
 

+ 1 - 0
src/Protocols/Http.php

@@ -241,6 +241,7 @@ class Http
         // Read file content from disk piece by piece and send to client.
         $doWrite = function () use ($connection, $handler, $length, $offsetEnd) {
             // Send buffer not full.
+            // @phpstan-ignore-next-line
             while ($connection->context->bufferFull === false) {
                 // Read from disk.
                 $size = 1024 * 1024;

+ 2 - 4
src/Protocols/Http/Session.php

@@ -262,10 +262,8 @@ class Session
             $this->delete($name);
             return;
         }
-        if (is_array($name)) {
-            foreach ($name as $key) {
-                unset($this->data[$key]);
-            }
+        foreach ($name as $key) {
+            unset($this->data[$key]);
         }
         $this->needSave = true;
     }

+ 1 - 3
src/Worker.php

@@ -876,7 +876,7 @@ class Worker
                 $propValue = (string)($worker->$prop ?? $worker->context->$prop);
                 $key = 'max' . ucfirst(strtolower($columnName)) . 'NameLength';
                 preg_match_all("/(<n>|<\/n>|<w>|<\/w>|<g>|<\/g>)/i", $propValue, $matches);
-                $placeHolderLength = !empty($matches) ? strlen(implode('', $matches[0])) : 0;
+                $placeHolderLength = !empty($matches[0]) ? strlen(implode('', $matches[0])) : 0;
                 $content .= str_pad($propValue, static::getUiColumnLength($key) + static::UI_SAFE_LENGTH + $placeHolderLength);
             }
             $content && static::safeEcho($content . PHP_EOL);
@@ -2509,9 +2509,7 @@ class Worker
         if ($messageCallback) {
             try {
                 if ($this->protocol !== null) {
-                    /** @var ProtocolInterface $parser */
                     $parser = $this->protocol;
-                    // @phpstan-ignore-next-line Left side of && is always true.
                     if ($parser && method_exists($parser, 'input')) {
                         while ($recvBuffer !== '') {
                             $len = $parser::input($recvBuffer, $connection);