diff --git a/src/Handler/Pipeline.php b/src/Handler/Pipeline.php index 00e3e8b2..4542f64f 100644 --- a/src/Handler/Pipeline.php +++ b/src/Handler/Pipeline.php @@ -15,7 +15,6 @@ * * @psalm-type TLast = Closure(mixed ...): mixed * - * @psalm-immutable * @internal * @psalm-internal Buggregator\Trap */ diff --git a/src/Sender/Console/Renderer/Monolog.php b/src/Sender/Console/Renderer/Monolog.php index 9cd364dc..071c6f17 100644 --- a/src/Sender/Console/Renderer/Monolog.php +++ b/src/Sender/Console/Renderer/Monolog.php @@ -28,6 +28,8 @@ public function isSupport(Frame $frame): bool public function render(OutputInterface $output, Frame $frame): void { + \assert($frame instanceof Frame\Monolog); + $payload = $frame->message; $levelColor = match (\strtolower($payload['level_name'])) { 'notice', 'info' => 'blue', @@ -41,7 +43,7 @@ public function render(OutputInterface $output, Frame $frame): void [ 'date' => $payload['datetime'], 'channel' => $payload['channel'] ?? '', - 'level' => $payload['level_name'] . '' ?? 'DEBUG', + 'level' => $payload['level_name'] ?? 'DEBUG', 'levelColor' => $levelColor, 'messages' => \explode("\n", $payload['message']), ] diff --git a/src/Sender/Console/Renderer/SentryEnvelope.php b/src/Sender/Console/Renderer/SentryEnvelope.php index b34736d0..1491daf2 100644 --- a/src/Sender/Console/Renderer/SentryEnvelope.php +++ b/src/Sender/Console/Renderer/SentryEnvelope.php @@ -26,6 +26,8 @@ public function isSupport(Frame $frame): bool public function render(OutputInterface $output, Frame $frame): void { + \assert($frame instanceof Frame\Sentry\SentryEnvelope); + Common::renderHeader1($output, 'SENTRY', 'ENVELOPE'); Header::renderMessageHeader($output, $frame->headers + ['timestamp' => $frame->time->format('U.u')]); diff --git a/src/Sender/Console/Renderer/SentryStore.php b/src/Sender/Console/Renderer/SentryStore.php index 43f51143..fc9867d3 100644 --- a/src/Sender/Console/Renderer/SentryStore.php +++ b/src/Sender/Console/Renderer/SentryStore.php @@ -26,6 +26,8 @@ public function isSupport(Frame $frame): bool public function render(OutputInterface $output, Frame $frame): void { + \assert($frame instanceof Frame\Sentry\SentryStore); + Common::renderHeader1($output, 'SENTRY'); try { diff --git a/src/Sender/Console/Renderer/Smtp.php b/src/Sender/Console/Renderer/Smtp.php index b49b83c4..5b40302d 100644 --- a/src/Sender/Console/Renderer/Smtp.php +++ b/src/Sender/Console/Renderer/Smtp.php @@ -25,6 +25,8 @@ public function isSupport(Frame $frame): bool public function render(OutputInterface $output, Frame $frame): void { + \assert($frame instanceof Frame\Smtp); + Common::renderHeader1($output, 'SMTP'); Common::renderMetadata($output, [ 'Time' => $frame->time->format('Y-m-d H:i:s.u'), diff --git a/src/Sender/Console/Renderer/VarDumper.php b/src/Sender/Console/Renderer/VarDumper.php index db465489..6dcfb948 100644 --- a/src/Sender/Console/Renderer/VarDumper.php +++ b/src/Sender/Console/Renderer/VarDumper.php @@ -32,6 +32,8 @@ public function isSupport(Frame $frame): bool public function render(OutputInterface $output, Frame $frame): void { + \assert($frame instanceof Frame\VarDumper); + $payload = @\unserialize(\base64_decode($frame->dump), ['allowed_classes' => [Data::class, Stub::class]]); // Impossible to decode the message, give up. diff --git a/src/Sender/Console/RendererInterface.php b/src/Sender/Console/RendererInterface.php index c9937263..c75e8e2d 100644 --- a/src/Sender/Console/RendererInterface.php +++ b/src/Sender/Console/RendererInterface.php @@ -18,7 +18,7 @@ interface RendererInterface public function isSupport(Frame $frame): bool; /** - * @param TFrame $frame + * @psalm-assert-if-true TFrame $frame */ public function render(OutputInterface $output, Frame $frame): void; } diff --git a/src/Sender/Console/Support/Files.php b/src/Sender/Console/Support/Files.php index d3162bff..387e5376 100644 --- a/src/Sender/Console/Support/Files.php +++ b/src/Sender/Console/Support/Files.php @@ -55,6 +55,9 @@ public static function renderFile( $output->writeln(" └───┘ $type"); } + /** + * @param int<0, max>|null $size + */ public static function normalizeSize(?int $size): ?string { if ($size === null) { @@ -62,8 +65,11 @@ public static function normalizeSize(?int $size): ?string } $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']; - $power = \floor(\log($size, 1024)); + $power = (int)\floor(\log($size, 1024)); $float = $power > 0 ? \round($size / (1024 ** $power), 2) : $size; - return $float . ' ' . $units[$power]; + + \assert($power >= 0 && $power <= 5); + + return \sprintf('%s %s', \number_format($float, 2), $units[$power]); } } diff --git a/src/Socket/SocketStream.php b/src/Socket/SocketStream.php index 5d0d3c34..aca31bfd 100644 --- a/src/Socket/SocketStream.php +++ b/src/Socket/SocketStream.php @@ -16,6 +16,7 @@ * Use {@see Server::$clientInflector} to wrap {@see Client} into {@see self}. * * @internal + * @implements IteratorAggregate */ final class SocketStream implements IteratorAggregate, StreamClient { diff --git a/src/Support/ProtobufCaster.php b/src/Support/ProtobufCaster.php index 234e1558..a7d26023 100644 --- a/src/Support/ProtobufCaster.php +++ b/src/Support/ProtobufCaster.php @@ -173,19 +173,4 @@ class: $ed->getClass(), return $values; } - - private static function extractViaPublic(Message $message, PublicDescriptor $descriptor): mixed - { - for ($i = 0; $i < $descriptor->getFieldCount(); $i++) { - /** @var FieldDescriptor $d */ - $d = $descriptor->getField($i); - // $d-> - if ($d->getType() !== GPBType::MESSAGE) { - continue; - } - - // todo what can we do? - // $descriptor = $d->getMessageType(); - } - } } diff --git a/src/Support/StreamHelper.php b/src/Support/StreamHelper.php index 5d2b40d4..02e6889f 100644 --- a/src/Support/StreamHelper.php +++ b/src/Support/StreamHelper.php @@ -56,6 +56,8 @@ public static function strpos(StreamInterface $stream, string $substr): int|fals } $stream->seek($caret, \SEEK_SET); + + \assert($result >= 0); return $result; } diff --git a/src/Traffic/Message/Headers.php b/src/Traffic/Message/Headers.php index 4e96ab03..53b986f9 100644 --- a/src/Traffic/Message/Headers.php +++ b/src/Traffic/Message/Headers.php @@ -30,10 +30,6 @@ public function hasHeader(string $header): bool */ public function getHeader(string $header): array { - if (!\is_string($header)) { - throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string'); - } - $header = \strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); if (!isset($this->headerNames[$header])) { return []; @@ -66,7 +62,7 @@ public function withHeader(string $header, $value): static public function withAddedHeader(string $header, string $value): static { - if (!\is_string($header) || '' === $header) { + if ('' === $header) { throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string'); } @@ -78,10 +74,6 @@ public function withAddedHeader(string $header, string $value): static public function withoutHeader(string $header): static { - if (!\is_string($header)) { - throw new \InvalidArgumentException('Header name must be an RFC 7230 compatible string'); - } - $normalized = \strtr($header, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'); if (!isset($this->headerNames[$normalized])) { return $this; diff --git a/src/Traffic/Message/Smtp.php b/src/Traffic/Message/Smtp.php index 996019cc..12d9c3e5 100644 --- a/src/Traffic/Message/Smtp.php +++ b/src/Traffic/Message/Smtp.php @@ -17,13 +17,6 @@ * @psalm-import-type FieldDataArray from Field * @psalm-import-type FileDataArray from File * - * @psalm-type SmtpDataArray = array{ - * protocol: array>, - * headers: array>, - * messages: array, - * attachments: array - * } - * * @internal */ final class Smtp implements JsonSerializable @@ -31,10 +24,10 @@ final class Smtp implements JsonSerializable use Headers; use StreamBody; - /** @var Field[] */ + /** @var list */ private array $messages = []; - /** @var File[] */ + /** @var list */ private array $attachments = []; /** @@ -57,9 +50,6 @@ public static function create(array $protocol, array $headers): self return new self($protocol, $headers); } - /** - * @param SmtpDataArray $data - */ public static function fromArray(array $data): self { $self = new self($data['protocol'], $data['headers']); @@ -73,9 +63,6 @@ public static function fromArray(array $data): self return $self; } - /** - * @return SmtpDataArray - */ public function jsonSerialize(): array { return [ diff --git a/src/Traffic/StreamClient.php b/src/Traffic/StreamClient.php index 717638af..4747779f 100644 --- a/src/Traffic/StreamClient.php +++ b/src/Traffic/StreamClient.php @@ -12,6 +12,7 @@ * Simple abstraction over a client two-way stream. * @internal * @psalm-internal Buggregator\Trap\Traffic + * @extends \IteratorAggregate */ interface StreamClient extends \IteratorAggregate {