Skip to content

Commit

Permalink
Phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Nov 7, 2024
1 parent f49f3d8 commit 124305d
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 24 deletions.
8 changes: 2 additions & 6 deletions src/Connection/AsyncUdpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 3 additions & 7 deletions src/Connection/TcpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class TcpConnection extends ConnectionInterface implements JsonSerializable
/**
* Cache.
*
* @var bool.
* @var bool
*/
protected static bool $enableCache = true;

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/Connection/UdpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Swoole.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down
1 change: 1 addition & 0 deletions src/Protocols/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-lowest - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-lowest - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - windows-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-stable - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-stable - windows-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - ubuntu-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - prefer-lowest - windows-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - macos-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.1 - prefer-lowest - windows-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-stable - windows-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - prefer-lowest - windows-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-stable - windows-latest

No error to ignore is reported on line 245.

Check failure on line 245 in src/Protocols/Http.php

View workflow job for this annotation

GitHub Actions / PHP 8.4 - prefer-lowest - windows-latest

No error to ignore is reported on line 245.
// Read from disk.
$size = 1024 * 1024;
Expand Down
6 changes: 2 additions & 4 deletions src/Protocols/Http/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>|<\/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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 124305d

Please sign in to comment.