Skip to content

Commit

Permalink
chore: fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jun 13, 2024
1 parent 344094d commit e41dc74
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 48 deletions.
11 changes: 5 additions & 6 deletions src/Handler/Http/Middleware/XHProfTrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,17 @@ private function processStore(ServerRequestInterface $request): ResponseInterfac
/** @var XHProfMessage $payload */
$payload = \json_decode((string) $request->getBody(), true, 96, \JSON_THROW_ON_ERROR);

Check failure on line 71 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

PHPDoc tag @var for variable $payload has no value type specified in iterable type array.

Check failure on line 71 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

PHPDoc tag @var for variable $payload has no value type specified in iterable type array.

Check failure on line 71 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

PHPDoc tag @var for variable $payload has no value type specified in iterable type array.

Check failure on line 71 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

PHPDoc tag @var for variable $payload has no value type specified in iterable type array.

Check warning on line 71 in src/Handler/Http/Middleware/XHProfTrap.php

View check run for this annotation

Codecov / codecov/patch

src/Handler/Http/Middleware/XHProfTrap.php#L71

Added line #L71 was not covered by tests

\is_array($payload['profile'] ?? null) && \is_array($payload['tags'] ?? null)

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Call to function is_array() with array will always evaluate to true.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Call to function is_array() with array will always evaluate to true.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Offset 'profile' on array{profile: array, tags: array, app_name: string, hostname: string, date: int<1, max>} on left side of ?? always exists and is not nullable.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Offset 'tags' on array{profile: array, tags: array, app_name: string, hostname: string, date: int<1, max>} on left side of ?? always exists and is not nullable.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Result of && is always true.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Call to function is_array() with array will always evaluate to true.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Call to function is_array() with array will always evaluate to true.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Offset 'profile' on array{profile: array, tags: array, app_name: string, hostname: string, date: int<1, max>} on left side of ?? always exists and is not nullable.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Offset 'tags' on array{profile: array, tags: array, app_name: string, hostname: string, date: int<1, max>} on left side of ?? always exists and is not nullable.

Check failure on line 73 in src/Handler/Http/Middleware/XHProfTrap.php

View workflow job for this annotation

GitHub Actions / phpstan (ubuntu-latest, 8.2, locked)

Result of && is always true.
or throw new \InvalidArgumentException('Invalid payload');

Check warning on line 74 in src/Handler/Http/Middleware/XHProfTrap.php

View check run for this annotation

Codecov / codecov/patch

src/Handler/Http/Middleware/XHProfTrap.php#L73-L74

Added lines #L73 - L74 were not covered by tests

$metadata = $payload;
unset($metadata['profile'], $metadata['tags'], $metadata['date']);

Check warning on line 77 in src/Handler/Http/Middleware/XHProfTrap.php

View check run for this annotation

Codecov / codecov/patch

src/Handler/Http/Middleware/XHProfTrap.php#L76-L77

Added lines #L76 - L77 were not covered by tests

isset($payload['profile'], $payload['tags'])
&& \is_array($payload['profile'])
&& \is_array($payload['tags'])
or throw new \InvalidArgumentException('Invalid payload');

/** @psalm-suppress MixedAssignment */
/** @var mixed $time */
$time = $request->getAttribute('begin_at');
$time = $time instanceof \DateTimeImmutable ? $time : new \DateTimeImmutable();

Check warning on line 81 in src/Handler/Http/Middleware/XHProfTrap.php

View check run for this annotation

Codecov / codecov/patch

src/Handler/Http/Middleware/XHProfTrap.php#L80-L81

Added lines #L80 - L81 were not covered by tests

/** @psalm-suppress MixedArgumentTypeCoercion */
\Fiber::suspend(
new Frame\Profiler(
payload: Frame\Profiler\Payload::new(
Expand Down
19 changes: 12 additions & 7 deletions src/Module/Profiler/Struct/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* app_name?: string,
* hostname?: string,
* filename?: string,
* filesize?: int<0, max>,
* ...
* }
*
Expand All @@ -30,6 +31,7 @@
final class Profile implements \JsonSerializable
{
public Peaks $peaks;
public Tree $calls;

/**
* @param Metadata $metadata
Expand All @@ -40,9 +42,10 @@ public function __construct(
public \DateTimeInterface $date = new \DateTimeImmutable(),
public array $metadata = [],
public array $tags = [],
public Tree $calls = new Tree(),
?Tree $calls = null,
?Peaks $peaks = null,
) {
$this->calls = $calls ?? new Tree();
if ($peaks === null) {
$this->peaks = new Peaks();

Check warning on line 50 in src/Module/Profiler/Struct/Profile.php

View check run for this annotation

Codecov / codecov/patch

src/Module/Profiler/Struct/Profile.php#L48-L50

Added lines #L48 - L50 were not covered by tests

Expand All @@ -57,38 +60,40 @@ public function __construct(

/**
* @param ProfileData $data
* @psalm-suppress all
*/
public static function fromArray(array $data): self

Check warning on line 65 in src/Module/Profiler/Struct/Profile.php

View check run for this annotation

Codecov / codecov/patch

src/Module/Profiler/Struct/Profile.php#L65

Added line #L65 was not covered by tests
{
$metadata = $data;
unset($metadata['tags'], $metadata['peaks'], $metadata['total_edges'], $metadata['date']);

Check warning on line 68 in src/Module/Profiler/Struct/Profile.php

View check run for this annotation

Codecov / codecov/patch

src/Module/Profiler/Struct/Profile.php#L67-L68

Added lines #L67 - L68 were not covered by tests

$self = new self(
return new self(
date: new \DateTimeImmutable('@' . $data['date']),
metadata: $metadata,
tags: $data['tags'],

Check warning on line 73 in src/Module/Profiler/Struct/Profile.php

View check run for this annotation

Codecov / codecov/patch

src/Module/Profiler/Struct/Profile.php#L70-L73

Added lines #L70 - L73 were not covered by tests
// todo calls from edges
peaks: Peaks::fromArray($data['peaks']),

Check warning on line 75 in src/Module/Profiler/Struct/Profile.php

View check run for this annotation

Codecov / codecov/patch

src/Module/Profiler/Struct/Profile.php#L75

Added line #L75 was not covered by tests
);

return $self;
}

/**
* @return ProfileData
* @psalm-suppress all
*/
public function jsonSerialize(): array

Check warning on line 83 in src/Module/Profiler/Struct/Profile.php

View check run for this annotation

Codecov / codecov/patch

src/Module/Profiler/Struct/Profile.php#L83

Added line #L83 was not covered by tests
{
/** @var array<non-empty-string, array> $edges */
$edges = \iterator_to_array($this->calls->getItemsSortedV1(
static fn(Branch $a, Branch $b): int => $b->item->cost->wt <=> $a->item->cost->wt,
));
return [
'date' => $this->date->getTimestamp(),
'app_name' => $this->metadata['app_name'] ?? '',
'hostname' => $this->metadata['hostname'] ?? '',
'filename' => $this->metadata['filename'] ?? '',
'tags' => $this->tags,
'peaks' => $this->peaks,
'edges' => \iterator_to_array($this->calls->getItemsSortedV1(
static fn(Branch $a, Branch $b): int => $b->item->cost->wt <=> $a->item->cost->wt,
)),
'edges' => $edges,
'total_edges' => $this->calls->count(),
];

Check warning on line 98 in src/Module/Profiler/Struct/Profile.php

View check run for this annotation

Codecov / codecov/patch

src/Module/Profiler/Struct/Profile.php#L86-L98

Added lines #L86 - L98 were not covered by tests
}
Expand Down
6 changes: 3 additions & 3 deletions src/Proto/Frame/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Buggregator\Trap\Proto\Frame;

use Buggregator\Trap\Module\Profiler\Struct\Profile;
use Buggregator\Trap\Proto\Frame;
use Buggregator\Trap\ProtoType;
use Buggregator\Trap\Support\Json;

/**
* @psalm-import-type Calls from \Buggregator\Trap\Proto\Frame\Profiler\Payload
* @psalm-import-type Metadata from \Buggregator\Trap\Proto\Frame\Profiler\Payload
* @psalm-import-type ProfileData from Profile
*
* @internal
* @psalm-internal Buggregator
Expand All @@ -26,7 +26,7 @@ public function __construct(

public static function fromString(string $payload, \DateTimeImmutable $time): static
{
/** @var array{type: non-empty-string}&Calls&Metadata $data */
/** @var array{type: non-empty-string}|ProfileData $data */
$data = Json::decode($payload);

return new self(Frame\Profiler\Payload::fromArray($data), $time);
Expand Down
16 changes: 11 additions & 5 deletions src/Proto/Frame/Profiler/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,21 @@ public static function new(
}

/**
* @param array{type: non-empty-string}&ProfileData $data
* @param array{type: non-empty-string}|ProfileData $data
*/
public static function fromArray(array $data, ?PayloadType $type = null): static

Check warning on line 50 in src/Proto/Frame/Profiler/Payload.php

View check run for this annotation

Codecov / codecov/patch

src/Proto/Frame/Profiler/Payload.php#L50

Added line #L50 was not covered by tests
{
/** @var \Closure(): Profile $provider */
/**
* @var \Closure(): Profile $provider
* @psalm-suppress all
*/
$provider = static fn(): Profile => Profile::fromArray($data);

Check warning on line 56 in src/Proto/Frame/Profiler/Payload.php

View check run for this annotation

Codecov / codecov/patch

src/Proto/Frame/Profiler/Payload.php#L56

Added line #L56 was not covered by tests

/** @psalm-suppress all */
$type ??= PayloadType::from($data['type']);

Check warning on line 59 in src/Proto/Frame/Profiler/Payload.php

View check run for this annotation

Codecov / codecov/patch

src/Proto/Frame/Profiler/Payload.php#L59

Added line #L59 was not covered by tests

return new self(
$type ?? PayloadType::from($data['type']),
$type,

Check warning on line 62 in src/Proto/Frame/Profiler/Payload.php

View check run for this annotation

Codecov / codecov/patch

src/Proto/Frame/Profiler/Payload.php#L62

Added line #L62 was not covered by tests
$provider,
);
}
Expand All @@ -64,15 +70,15 @@ public function getProfile(): Profile
}

/**
* @return array{type: non-empty-string}&ProfileData
* @return array{type: non-empty-string}|ProfileData
*/
public function toArray(): array
{
return ['type' => $this->type->value] + $this->getProfile()->jsonSerialize();

Check warning on line 77 in src/Proto/Frame/Profiler/Payload.php

View check run for this annotation

Codecov / codecov/patch

src/Proto/Frame/Profiler/Payload.php#L77

Added line #L77 was not covered by tests
}

/**
* @return array{type: non-empty-string}&ProfileData
* @return array{type: non-empty-string}|ProfileData
*/
public function jsonSerialize(): array
{
Expand Down
13 changes: 8 additions & 5 deletions src/Sender/Console/Renderer/Profiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public function isSupport(Frame $frame): bool
return $frame->type === ProtoType::Profiler;
}

/**
* @psalm-suppress MixedAssignment
*/
public function render(OutputInterface $output, Frame $frame): void
{
\assert($frame instanceof Frame\Profiler);
Expand All @@ -37,11 +40,11 @@ public function render(OutputInterface $output, Frame $frame): void
$data = [];
isset($metadata['date']) && \is_numeric($metadata['date'])
and $data['Time'] = new \DateTimeImmutable('@' . $metadata['date']);
isset($metadata['app_name']) and $data['App name'] = $metadata['app_name'];
isset($metadata['hostname']) and $data['Hostname'] = $metadata['hostname'];
isset($metadata['filename']) and $data['File name'] = $metadata['filename'] . (
isset($metadata['filesize']) && \is_int($metadata['filesize'])
? ' (' . Measure::memory($metadata['filesize']) . ')'
\is_string($m = $metadata['app_name'] ?? null) and $data['App name'] = $m;
\is_string($m = $metadata['hostname'] ?? null) and $data['Hostname'] = $m;
\is_string($m = $metadata['filename'] ?? null) and $data['File name'] = $m . (
\is_int($m = $metadata['filesize'] ?? null) && $m >= 0
? ' (' . Measure::memory($m) . ')'
: ''

Check warning on line 48 in src/Sender/Console/Renderer/Profiler.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Console/Renderer/Profiler.php#L43-L48

Added lines #L43 - L48 were not covered by tests
);
$data['Num edges'] = $profile->calls->count();

Check warning on line 50 in src/Sender/Console/Renderer/Profiler.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Console/Renderer/Profiler.php#L50

Added line #L50 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion src/Sender/Console/Renderer/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function render(OutputInterface $output, Frame $frame): void
\array_map(static fn($attach) => [
'CID' => $attach->getEmbeddingId(),
'Name' => $attach->getClientFilename(),
'Size' => Measure::memory($attach->getSize()),
'Size' => $attach->getSize() === null ? 'unknown size' : Measure::memory($attach->getSize()),
'MIME' => $attach->getClientMediaType(),
], $embeddings),
'compact',

Check warning on line 95 in src/Sender/Console/Renderer/Smtp.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Console/Renderer/Smtp.php#L86-L95

Added lines #L86 - L95 were not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion src/Sender/Console/Support/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function renderFile(
: \str_pad(\substr($fileName, $dotPos + 1), 3, ' ', \STR_PAD_BOTH);

// File size
$sizeStr = Measure::memory($size) ?? 'unknown size';
$sizeStr = $size === null ? 'unknown size' : Measure::memory($size);

Check warning on line 45 in src/Sender/Console/Support/Files.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Console/Support/Files.php#L45

Added line #L45 was not covered by tests

// Header with top border
$output->writeln("<bg=black;fg=magenta> ┌───┐</> <info>$fileName</info>");
Expand Down
2 changes: 1 addition & 1 deletion src/Sender/Console/Support/Tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function renderKeyValueTable(OutputInterface $output, string $titl
}

/**
* @param array<array-key, array<array-key, scalar>> $data
* @param array<array-key, array<array-key, scalar|null>> $data
* @param 'default'|'borderless'|'compact'|'symfony-style-guide'|'box'|'box-double' $style
*/
public static function renderMultiColumnTable(

Check warning on line 50 in src/Sender/Console/Support/Tables.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Console/Support/Tables.php#L50

Added line #L50 was not covered by tests
Expand Down
2 changes: 1 addition & 1 deletion src/Sender/Frontend/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Event implements \JsonSerializable
/**
* @param non-empty-string $uuid
* @param non-empty-string $type
* @param \ArrayAccess<non-empty-string, Asset>|null $assets
* @param \ArrayAccess<non-empty-string, Asset>&\Traversable<non-empty-string, Asset>|null $assets
*/
public function __construct(
public readonly string $uuid,
Expand Down
2 changes: 1 addition & 1 deletion src/Sender/Frontend/Mapper/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function map(HttpFrame $frame): Event
$request = $frame->request;

$uri = \ltrim($request->getUri()->getPath(), '/');
/** @var \ArrayAccess<non-empty-string, Event\Asset> $assets */
/** @var \ArrayObject<non-empty-string, Event\Asset> $assets */
$assets = new \ArrayObject();

return new Event(
Expand Down
10 changes: 5 additions & 5 deletions src/Sender/Frontend/Mapper/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ private static function assetLink(string $uuid, Event\Asset $asset): string
}

/**
* @return \ArrayAccess<non-empty-string, Event\Asset>
* @return \ArrayObject<non-empty-string, Event\Asset>
*/
private static function fetchAssets(SmtpMessage $message): \ArrayAccess
private static function fetchAssets(SmtpMessage $message): \ArrayObject

Check warning on line 56 in src/Sender/Frontend/Mapper/Smtp.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Frontend/Mapper/Smtp.php#L56

Added line #L56 was not covered by tests
{
/** @var \ArrayAccess<non-empty-string, Event\Asset> $assets */
/** @var \ArrayObject<non-empty-string, Event\Asset> $assets */
$assets = new \ArrayObject();

Check warning on line 59 in src/Sender/Frontend/Mapper/Smtp.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Frontend/Mapper/Smtp.php#L59

Added line #L59 was not covered by tests

foreach ($message->getAttachments() as $attachment) {
Expand Down Expand Up @@ -83,9 +83,9 @@ private static function asset(File $attachment): Event\Asset

/**
* @param non-empty-string $uuid
* @param \ArrayAccess<non-empty-string, Event\Asset> $assets
* @param \ArrayAccess<non-empty-string, Event\Asset>&\Traversable<non-empty-string, Event\Asset> $assets
*/
private static function html(string $uuid, SmtpMessage $message, \ArrayAccess $assets): string
private static function html(string $uuid, SmtpMessage $message, \ArrayAccess&\Traversable $assets): string

Check warning on line 88 in src/Sender/Frontend/Mapper/Smtp.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Frontend/Mapper/Smtp.php#L88

Added line #L88 was not covered by tests
{
$result = $message->getMessage(MessageFormat::Html)?->getValue() ?? '';

Check warning on line 90 in src/Sender/Frontend/Mapper/Smtp.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Frontend/Mapper/Smtp.php#L90

Added line #L90 was not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion src/Sender/Frontend/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function smtpAttachments(string $uuid): Attachments|Success
}

$attaches = [];
foreach ($event->assets as $attachment) {
foreach ($event->assets ?? [] as $attachment) {
$attachment instanceof AttachedFile and $attaches[] = $attachment;

Check warning on line 80 in src/Sender/Frontend/Service.php

View check run for this annotation

Codecov / codecov/patch

src/Sender/Frontend/Service.php#L78-L80

Added lines #L78 - L80 were not covered by tests
}

Expand Down
10 changes: 3 additions & 7 deletions src/Support/Measure.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@
final class Measure
{
/**
* @param int<0, max>|null $size
* @return non-empty-string|null
* @param int<0, max> $size
* @return non-empty-string
*/
public static function memory(?int $size): ?string
public static function memory(int $size): string

Check warning on line 17 in src/Support/Measure.php

View check run for this annotation

Codecov / codecov/patch

src/Support/Measure.php#L17

Added line #L17 was not covered by tests
{
if ($size === null) {
return null;
}

$units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB'];
$power = (int) \floor(\log($size, 1024));
$float = $power > 0 ? \round($size / (1024 ** $power), 2) : $size;

Check warning on line 21 in src/Support/Measure.php

View check run for this annotation

Codecov / codecov/patch

src/Support/Measure.php#L19-L21

Added lines #L19 - L21 were not covered by tests
Expand Down
11 changes: 10 additions & 1 deletion src/Support/Stream/Base64DecodeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
namespace Buggregator\Trap\Support\Stream;

/**
* @psalm-suppress all
*
* @internal
* @psalm-internal Buggregator\Trap
*
* @link https://www.php.net/manual/function.stream-filter-register.php
*/
final class Base64DecodeFilter extends \php_user_filter
Expand All @@ -15,12 +18,18 @@ final class Base64DecodeFilter extends \php_user_filter

private string $buffer = '';

/**
* @param resource $in
* @param resource $out
* @param int<0, max> $consumed
*/
public function filter($in, $out, &$consumed, bool $closing): int
{
// Buffer size
$bs = \strlen($this->buffer);

while ($bucket = \stream_bucket_make_writeable($in)) {
/** @var int<1, max> $len */
$len = $bs + $bucket->datalen;
$d = $len % 4;

Expand All @@ -43,7 +52,7 @@ public function filter($in, $out, &$consumed, bool $closing): int
}

// Decode part of the data
$bucket->data = \base64_decode($this->buffer . \substr($bucket->data, 0, -$d), true);
$bucket->data = \base64_decode($this->buffer . \substr($bucket->data, 0, -$d));
$consumed += $bucket->datalen;
$this->buffer = \substr($bucket->data, -$d);

Expand Down
8 changes: 6 additions & 2 deletions src/Support/StreamHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,25 @@ public static function unzipBody(ServerRequestInterface $request): ServerRequest
/**
* @param array<non-empty-string|int, mixed> $readFilters filter name => filter options
* @param array<non-empty-string|int, mixed> $writeFilters filter name => filter options
*
* @psalm-suppress UnusedFunctionCall
*/
public static function createFileStream(array $readFilters = [], array $writeFilters = []): StreamInterface
{
$stream = \fopen('php://temp/maxmemory:' . self::MAX_FILE_MEMORY_SIZE, 'w+b');

/** @var mixed $options */
foreach ($readFilters as $filter => $options) {
\is_string($filter)
? \stream_filter_append($stream, $filter, \STREAM_FILTER_READ, $options)
: \stream_filter_append($stream, $options, \STREAM_FILTER_READ);
: \stream_filter_append($stream, (string) $options, \STREAM_FILTER_READ);

Check warning on line 145 in src/Support/StreamHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Support/StreamHelper.php#L143-L145

Added lines #L143 - L145 were not covered by tests
}

/** @var mixed $options */
foreach ($writeFilters as $filter => $options) {
\is_string($filter)
? \stream_filter_append($stream, $filter, \STREAM_FILTER_WRITE, $options)

Check warning on line 151 in src/Support/StreamHelper.php

View check run for this annotation

Codecov / codecov/patch

src/Support/StreamHelper.php#L151

Added line #L151 was not covered by tests
: \stream_filter_append($stream, $options, \STREAM_FILTER_WRITE);
: \stream_filter_append($stream, (string) $options, \STREAM_FILTER_WRITE);
}

return Stream::create($stream);
Expand Down
2 changes: 1 addition & 1 deletion src/Traffic/Message/Multipart/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function getClientFilename(): ?string

public function getClientMediaType(): ?string
{
return \explode(';', $this->getHeader('Content-Type')[0], 2)[0] ?? null;
return \explode(';', $this->getHeader('Content-Type')[0] ?? '', 2)[0] ?? null;
}

public function isEmbedded(): bool

Check warning on line 121 in src/Traffic/Message/Multipart/File.php

View check run for this annotation

Codecov / codecov/patch

src/Traffic/Message/Multipart/File.php#L121

Added line #L121 was not covered by tests
Expand Down

0 comments on commit e41dc74

Please sign in to comment.