diff --git a/src/Connection/AsyncUdpConnection.php b/src/Connection/AsyncUdpConnection.php index d17fa5b31..0ffd3a674 100644 --- a/src/Connection/AsyncUdpConnection.php +++ b/src/Connection/AsyncUdpConnection.php @@ -108,9 +108,7 @@ public function baseRead($socket): void 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 @@ public function close(mixed $data = null, bool $raw = false): void 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; } diff --git a/src/Connection/TcpConnection.php b/src/Connection/TcpConnection.php index ba7539c75..b0bec4794 100644 --- a/src/Connection/TcpConnection.php +++ b/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 @@ public function send(mixed $sendBuffer, bool $raw = false): bool|null // 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 @@ public function baseRead($socket, bool $checkEof = true): void $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) { diff --git a/src/Connection/UdpConnection.php b/src/Connection/UdpConnection.php index dac804107..7d301ffdf 100644 --- a/src/Connection/UdpConnection.php +++ b/src/Connection/UdpConnection.php @@ -65,9 +65,7 @@ public function __construct( 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; } diff --git a/src/Events/Swoole.php b/src/Events/Swoole.php index ff59d63d7..6862a2ce5 100644 --- a/src/Events/Swoole.php +++ b/src/Events/Swoole.php @@ -39,7 +39,7 @@ final class Swoole implements EventInterface /** * All listeners for write event. * - * @var array + * @var array */ private array $writeEvents = []; diff --git a/src/Protocols/Http.php b/src/Protocols/Http.php index 1afaba1c2..4bf4381a8 100644 --- a/src/Protocols/Http.php +++ b/src/Protocols/Http.php @@ -241,6 +241,7 @@ protected static function sendStream(TcpConnection $connection, $handler, int $o // 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; diff --git a/src/Protocols/Http/Session.php b/src/Protocols/Http/Session.php index 5d92f0b86..6554e5f8a 100644 --- a/src/Protocols/Http/Session.php +++ b/src/Protocols/Http/Session.php @@ -262,10 +262,8 @@ public function forget(array|string $name): void $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; } diff --git a/src/Worker.php b/src/Worker.php index f63244ab4..e802be1d1 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -876,7 +876,7 @@ protected static function displayUI(): void $propValue = (string)($worker->$prop ?? $worker->context->$prop); $key = 'max' . ucfirst(strtolower($columnName)) . 'NameLength'; preg_match_all("/(|<\/n>||<\/w>||<\/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 @@ protected function acceptUdpConnection(mixed $socket): void 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);