From 6fdbaf69d22696424cf5580436a92471ff707620 Mon Sep 17 00:00:00 2001 From: Evert Jan Hakvoort <31619091+EJTJ3@users.noreply.github.com> Date: Mon, 28 Oct 2024 19:42:23 +0100 Subject: [PATCH] fix: phpstan level 9 errors (#25) --- src/Connection/HMsg.php | 3 +++ src/Connection/NatsConnection.php | 1 + src/Connection/ServerInfo.php | 2 +- src/Encoder/EncoderInterface.php | 9 ++++++--- src/Encoder/JsonEncoder.php | 3 ++- src/Logger/NullLogger.php | 2 +- 6 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Connection/HMsg.php b/src/Connection/HMsg.php index bbc8fdb..15e3b90 100644 --- a/src/Connection/HMsg.php +++ b/src/Connection/HMsg.php @@ -10,6 +10,9 @@ final class HMsg implements MessageInterface { + /** + * @var array + */ private array $headers; public ?string $payload; diff --git a/src/Connection/NatsConnection.php b/src/Connection/NatsConnection.php index fce4b31..ed9df24 100644 --- a/src/Connection/NatsConnection.php +++ b/src/Connection/NatsConnection.php @@ -194,6 +194,7 @@ public function validatePing(): void */ public function request(string $subject, string $payload = '', ?string $reply = null): MessageInterface { + /** @var string $replySubject */ $replySubject = StringUtil::isEmpty($reply) ? self::createSid() : $reply; $sub = $this->subscribe($replySubject, null); diff --git a/src/Connection/ServerInfo.php b/src/Connection/ServerInfo.php index b54367d..803665d 100644 --- a/src/Connection/ServerInfo.php +++ b/src/Connection/ServerInfo.php @@ -134,7 +134,7 @@ public function getMaxPayload(): int return $this->maxPayload; } - public function getClientId(): int + public function getClientId(): ?int { return $this->clientId; } diff --git a/src/Encoder/EncoderInterface.php b/src/Encoder/EncoderInterface.php index 6dc4980..9938173 100644 --- a/src/Encoder/EncoderInterface.php +++ b/src/Encoder/EncoderInterface.php @@ -4,12 +4,15 @@ namespace EJTJ3\PhpNats\Encoder; -/** - * @author Evert Jan Hakvoort - */ interface EncoderInterface { + /** + * @param object|string|array $payload + */ public function encode(object|string|array $payload): string; + /** + * @return array + */ public function decode(string $payload): object|array; } diff --git a/src/Encoder/JsonEncoder.php b/src/Encoder/JsonEncoder.php index 1e062ab..37c7580 100644 --- a/src/Encoder/JsonEncoder.php +++ b/src/Encoder/JsonEncoder.php @@ -17,10 +17,11 @@ public function encode(object|string|array $payload): string } /** - * @return array + * @return array */ public function decode(string $payload): array { + // @phpstan-ignore-next-line return json_decode($payload, true); } } diff --git a/src/Logger/NullLogger.php b/src/Logger/NullLogger.php index 68fcd99..248fec6 100644 --- a/src/Logger/NullLogger.php +++ b/src/Logger/NullLogger.php @@ -9,7 +9,7 @@ final class NullLogger extends AbstractLogger implements LoggerInterface { - public function log($level, $message, array $context = []): void + public function log($level, string|\Stringable $message, array $context = []): void { } }