diff --git a/src/Stopwatch.php b/src/Stopwatch.php index 1b11291..c2a9e7b 100644 --- a/src/Stopwatch.php +++ b/src/Stopwatch.php @@ -34,7 +34,7 @@ public static function start(): self } /** - * @param array{int|string, int|float|string|null|bool|Stringable}|null $metadata + * @param array{int|string, mixed}|null $metadata */ public function checkpoint(string $label, ?array $metadata = null): self { @@ -46,7 +46,7 @@ public function checkpoint(string $label, ?array $metadata = null): self /** * @alias * @see self::checkpoint() - * @param array{int|string, int|float|string|null|bool|Stringable}|null $metadata + * @param array{int|string, mixed}|null $metadata */ public function lap(string $label, ?array $metadata = null): self { diff --git a/src/StopwatchCheckpoint.php b/src/StopwatchCheckpoint.php index 176ae52..80bc2bb 100644 --- a/src/StopwatchCheckpoint.php +++ b/src/StopwatchCheckpoint.php @@ -24,7 +24,7 @@ public string $timeSinceLastCheckpointFormatted; /** - * @param array{int|string, int|float|string|null|bool|Stringable}|null $metadata + * @param array{int|string, mixed}|null $metadata */ public function __construct( public string $label, @@ -91,7 +91,13 @@ private function renderMetadata(): string } $contents = collect($this->metadata) - ->implode(static fn (int|float|string|null|bool|Stringable $value, string|int $key): string => "{$key}: {$value}
"); + ->implode(static function (mixed $value, string|int $key): string { + if (! is_scalar($value) && ! $value instanceof Stringable) { + $value = 'non-scalar value (' . gettype($value) . ')'; + } + + return "{$key}: {$value}
"; + }); return << @@ -104,7 +110,7 @@ private function renderMetadata(): string * @return array{ * label: string, * time: string, - * metadata: array{int|string, int|float|string|null|bool|Stringable}|null, + * metadata: array{int|string, mixed}|null, * totalTimeElapsedMs: int, * totalTimeElapsedFormatted: string, * timeSinceLastCheckpointMs: int, diff --git a/src/StopwatchCheckpointCollection.php b/src/StopwatchCheckpointCollection.php index 506f36f..46001cc 100644 --- a/src/StopwatchCheckpointCollection.php +++ b/src/StopwatchCheckpointCollection.php @@ -4,7 +4,6 @@ use Carbon\CarbonImmutable; use Illuminate\Support\Collection; -use Stringable; /** * @extends Collection @@ -14,7 +13,7 @@ final class StopwatchCheckpointCollection extends Collection { /** - * @param array{int|string, int|float|string|null|bool|Stringable}|null $metadata + * @param array{int|string, mixed}|null $metadata */ public function addCheckpoint(string $label, ?array $metadata, CarbonImmutable $stopwatchStartTime): self {