diff --git a/composer.json b/composer.json index d7b8699..1af6466 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,7 @@ "amphp/phpunit-util": "^3", "phpunit/phpunit": "^9", "amphp/php-cs-fixer-config": "^2", - "psalm/phar": "^5.4" + "psalm/phar": "5.22.1" }, "autoload": { "psr-4": { diff --git a/src/Payload.php b/src/Payload.php index a1755ae..04c04ba 100644 --- a/src/Payload.php +++ b/src/Payload.php @@ -130,7 +130,7 @@ public function onClose(\Closure $onClose): void } /** - * Buffers entire stream before returning. Use {@see self::buffer()} to optionally provide a{@see Cancellation} + * Buffers entire stream before returning. Use {@see self::buffer()} to optionally provide a {@see Cancellation} * and/or length limit. * * @throws BufferException|StreamException diff --git a/src/ReadableResourceStream.php b/src/ReadableResourceStream.php index cfeb5c6..644c4b9 100644 --- a/src/ReadableResourceStream.php +++ b/src/ReadableResourceStream.php @@ -101,6 +101,8 @@ public function __construct($stream, int $chunkSize = self::DEFAULT_CHUNK_SIZE) $useSingleRead, $onClose, ): void { + \assert($stream !== null, 'Watcher invoked with null stream'); + \set_error_handler(self::$errorHandler); try { diff --git a/src/WritableResourceStream.php b/src/WritableResourceStream.php index a881e5b..9fffd3a 100644 --- a/src/WritableResourceStream.php +++ b/src/WritableResourceStream.php @@ -28,6 +28,7 @@ final class WritableResourceStream implements WritableStream, ResourceStream private bool $writable = true; + /** @var positive-int|null */ private ?int $chunkSize = null; /** @var \Closure():bool */ @@ -72,8 +73,8 @@ public function __construct($stream, ?int $chunkSize = null) $resource = &$this->resource; $this->callbackId = EventLoop::disable(EventLoop::onWritable( - $stream, - static function ($callbackId, $stream) use ( + $this->resource, + static function ($callbackId) use ( $writes, &$chunkSize, &$writable, @@ -98,7 +99,8 @@ static function ($callbackId, $stream) use ( continue; } - if (!\is_resource($stream)) { + /** @psalm-suppress TypeDoesNotContainType */ + if (!\is_resource($resource)) { $writable = false; $suspension?->resume(static fn () => throw new ClosedException("The stream was closed by the peer")); continue; @@ -119,9 +121,9 @@ static function ($callbackId, $stream) use ( // Customer error handler needed since fwrite() emits E_WARNING if the pipe is broken or the buffer is full. // Use conditional, because PHP doesn't like getting null passed if ($chunkSize) { - $written = \fwrite($stream, $data, $chunkSize); + $written = \fwrite($resource, $data, $chunkSize); } else { - $written = \fwrite($stream, $data); + $written = \fwrite($resource, $data); } } finally { \restore_error_handler(); @@ -151,6 +153,7 @@ static function ($callbackId, $stream) use ( $firstWrite = false; } } finally { + /** @psalm-suppress RedundantCondition */ if (!$writable && \is_resource($resource)) { $meta = \stream_get_meta_data($resource); if (\str_contains($meta["mode"], "+")) { diff --git a/src/functions.php b/src/functions.php index 9975424..17cd3f9 100644 --- a/src/functions.php +++ b/src/functions.php @@ -12,10 +12,12 @@ ); } // @codeCoverageIgnoreEnd +/** @psalm-suppress PossiblyInvalidArgument */ if (!\defined('STDOUT')) { \define('STDOUT', \fopen('php://stdout', 'wb')); } +/** @psalm-suppress PossiblyInvalidArgument */ if (!\defined('STDERR')) { \define('STDERR', \fopen('php://stderr', 'wb')); }