Skip to content

Commit

Permalink
Fix psalm issues on level 5
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Nov 19, 2023
1 parent eedf6f6 commit af2c79a
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 44 deletions.
1 change: 0 additions & 1 deletion src/Handler/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*
* @psalm-type TLast = Closure(mixed ...): mixed
*
* @psalm-immutable
* @internal
* @psalm-internal Buggregator\Trap
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Sender/Console/Renderer/Monolog.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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']),
]
Expand Down
2 changes: 2 additions & 0 deletions src/Sender/Console/Renderer/SentryEnvelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]);

Expand Down
2 changes: 2 additions & 0 deletions src/Sender/Console/Renderer/SentryStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/Sender/Console/Renderer/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
2 changes: 2 additions & 0 deletions src/Sender/Console/Renderer/VarDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Sender/Console/RendererInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
10 changes: 8 additions & 2 deletions src/Sender/Console/Support/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,21 @@ public static function renderFile(
$output->writeln("<bg=black;fg=magenta> └───┘</> <fg=gray>$type</>");
}

/**
* @param int<0, max>|null $size
*/
public static function normalizeSize(?int $size): ?string
{
if ($size === null) {
return null;
}

$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]);
}
}
1 change: 1 addition & 0 deletions src/Socket/SocketStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* Use {@see Server::$clientInflector} to wrap {@see Client} into {@see self}.
*
* @internal
* @implements IteratorAggregate<int, string>
*/
final class SocketStream implements IteratorAggregate, StreamClient
{
Expand Down
15 changes: 0 additions & 15 deletions src/Support/ProtobufCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
2 changes: 2 additions & 0 deletions src/Support/StreamHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public static function strpos(StreamInterface $stream, string $substr): int|fals
}

$stream->seek($caret, \SEEK_SET);

\assert($result >= 0);
return $result;
}

Expand Down
10 changes: 1 addition & 9 deletions src/Traffic/Message/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down Expand Up @@ -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');
}

Expand All @@ -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;
Expand Down
17 changes: 2 additions & 15 deletions src/Traffic/Message/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,17 @@
* @psalm-import-type FieldDataArray from Field
* @psalm-import-type FileDataArray from File
*
* @psalm-type SmtpDataArray = array{
* protocol: array<string, string|list<string>>,
* headers: array<string, list<string>>,
* messages: array<int, FieldDataArray>,
* attachments: array<int, FileDataArray>
* }
*
* @internal
*/
final class Smtp implements JsonSerializable
{
use Headers;
use StreamBody;

/** @var Field[] */
/** @var list<Field> */
private array $messages = [];

/** @var File[] */
/** @var list<File> */
private array $attachments = [];

/**
Expand All @@ -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']);
Expand All @@ -73,9 +63,6 @@ public static function fromArray(array $data): self
return $self;
}

/**
* @return SmtpDataArray
*/
public function jsonSerialize(): array
{
return [
Expand Down
1 change: 1 addition & 0 deletions src/Traffic/StreamClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* Simple abstraction over a client two-way stream.
* @internal
* @psalm-internal Buggregator\Trap\Traffic
* @extends \IteratorAggregate<int, string>
*/
interface StreamClient extends \IteratorAggregate
{
Expand Down

0 comments on commit af2c79a

Please sign in to comment.