From 5b7b0fa12da5ae9294564e80efe4bf6ec2f536d6 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Sun, 19 Nov 2023 16:47:14 +0400 Subject: [PATCH] Fix psalm issues --- psalm.xml | 1 + src/Handler/Http/Handler/Websocket.php | 2 +- src/Handler/Pipeline.php | 2 +- src/Proto/Frame/Http.php | 2 +- src/Proto/Frame/Sentry/SentryStore.php | 2 +- src/Sender/Console/Renderer/Sentry/Exceptions.php | 2 -- src/Sender/Console/Renderer/Sentry/Header.php | 2 -- src/Socket/Client.php | 6 ++++-- src/Traffic/Message/Headers.php | 2 +- src/Traffic/StreamClient.php | 2 +- src/functions.php | 1 + 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/psalm.xml b/psalm.xml index 0153171d..99fbec79 100644 --- a/psalm.xml +++ b/psalm.xml @@ -15,6 +15,7 @@ + diff --git a/src/Handler/Http/Handler/Websocket.php b/src/Handler/Http/Handler/Websocket.php index bcfbb141..9d6dbf9d 100644 --- a/src/Handler/Http/Handler/Websocket.php +++ b/src/Handler/Http/Handler/Websocket.php @@ -66,7 +66,7 @@ public function handle(StreamClient $streamClient, ServerRequestInterface $reque } /** - * Todo: extract to a separate Websocket service + * Todo: extract to a separated Websocket service * * @return iterable */ diff --git a/src/Handler/Pipeline.php b/src/Handler/Pipeline.php index 4542f64f..2e1c4d36 100644 --- a/src/Handler/Pipeline.php +++ b/src/Handler/Pipeline.php @@ -29,7 +29,7 @@ final class Pipeline /** * @param iterable $middlewares * @param non-empty-string $method - * @param Closure(): TReturn $last + * @param Closure(mixed...): TReturn $last * @param class-string|string $returnType */ private function __construct( diff --git a/src/Proto/Frame/Http.php b/src/Proto/Frame/Http.php index fc2b9009..69cdf8f4 100644 --- a/src/Proto/Frame/Http.php +++ b/src/Proto/Frame/Http.php @@ -50,7 +50,7 @@ public static function fromString(string $payload, DateTimeImmutable $time): sta $request = new ServerRequest( $payload['method'] ?? 'GET', $payload['uri'] ?? '/', - (array)$payload['headers'] ?? [], + (array)($payload['headers'] ?? []), $payload['body'] ?? '', $payload['protocolVersion'] ?? '1.1', $payload['serverParams'] ?? [], diff --git a/src/Proto/Frame/Sentry/SentryStore.php b/src/Proto/Frame/Sentry/SentryStore.php index 67f5c23e..81034df3 100644 --- a/src/Proto/Frame/Sentry/SentryStore.php +++ b/src/Proto/Frame/Sentry/SentryStore.php @@ -39,7 +39,7 @@ final class SentryStore extends Frame\Sentry * filename: non-empty-string, * lineno: positive-int, * abs_path: non-empty-string, - * context_line: non-empty-string, + * context_line: non-empty-string * } * } * }> diff --git a/src/Sender/Console/Renderer/Sentry/Exceptions.php b/src/Sender/Console/Renderer/Sentry/Exceptions.php index 70dffc81..c6d0f333 100644 --- a/src/Sender/Console/Renderer/Sentry/Exceptions.php +++ b/src/Sender/Console/Renderer/Sentry/Exceptions.php @@ -10,8 +10,6 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * @implements RendererInterface - * * @internal * @psalm-internal Buggregator\Trap\Sender\Console\Renderer */ diff --git a/src/Sender/Console/Renderer/Sentry/Header.php b/src/Sender/Console/Renderer/Sentry/Header.php index b207f16c..99818fb8 100644 --- a/src/Sender/Console/Renderer/Sentry/Header.php +++ b/src/Sender/Console/Renderer/Sentry/Header.php @@ -11,8 +11,6 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * @implements RendererInterface - * * @internal */ final class Header diff --git a/src/Socket/Client.php b/src/Socket/Client.php index ed026fce..d90523d6 100644 --- a/src/Socket/Client.php +++ b/src/Socket/Client.php @@ -71,14 +71,17 @@ public function process(): void throw new \RuntimeException('Socket select failed.'); } + /** @psalm-suppress RedundantCondition */ if ($read !== []) { $this->readMessage(); } + /** @psalm-suppress RedundantCondition */ if ($write !== [] && $this->writeQueue !== []) { $this->writeQueue(); } + /** @psalm-suppress RedundantCondition */ if ($except !== [] || \socket_last_error($this->socket) !== 0) { throw new \RuntimeException('Socket exception.'); } @@ -150,14 +153,13 @@ private function readMessage(): void /** * @param positive-int $length - * - * @return non-empty-string */ private function readBytes(int $length, bool $canBeLess = false): string { while (($left = $length - \strlen($this->readBuffer)) > 0) { $data = ''; $read = @\socket_recv($this->socket, $data, $left, 0); + /** @psalm-suppress TypeDoesNotContainNull */ if ($read === false || $data === null) { if ($this->readBuffer !== '') { $result = $this->readBuffer; diff --git a/src/Traffic/Message/Headers.php b/src/Traffic/Message/Headers.php index 53b986f9..3be3a37f 100644 --- a/src/Traffic/Message/Headers.php +++ b/src/Traffic/Message/Headers.php @@ -129,7 +129,7 @@ private function setHeaders(array $headers): void */ private function validateAndTrimHeader(string $header, $values): array { - if (!\is_string($header) || 1 !== \preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@D", $header)) { + if (1 !== \preg_match("@^[!#$%&'*+.^_`|~0-9A-Za-z-]+$@D", $header)) { throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string'); } diff --git a/src/Traffic/StreamClient.php b/src/Traffic/StreamClient.php index 4747779f..b64a6dc7 100644 --- a/src/Traffic/StreamClient.php +++ b/src/Traffic/StreamClient.php @@ -11,7 +11,7 @@ /** * Simple abstraction over a client two-way stream. * @internal - * @psalm-internal Buggregator\Trap\Traffic + * @psalm-internal Buggregator\Trap * @extends \IteratorAggregate */ interface StreamClient extends \IteratorAggregate diff --git a/src/functions.php b/src/functions.php index 0cbfa4fb..764279f1 100644 --- a/src/functions.php +++ b/src/functions.php @@ -57,6 +57,7 @@ function trap(mixed ...$values): void // Dump sequence of values foreach ($values as $key => $value) { + /** @psalm-suppress TooManyArguments */ VarDumper::dump($value, $key); } }