Skip to content

Commit

Permalink
Update Psalm and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Feb 17, 2024
1 parent a868219 commit 1c31c9e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion src/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/ReadableResourceStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 8 additions & 5 deletions src/WritableResourceStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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"], "+")) {
Expand Down
2 changes: 2 additions & 0 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down

0 comments on commit 1c31c9e

Please sign in to comment.