Cleanup value formatting code

This commit is contained in:
2025-03-16 21:37:03 +01:00
parent 9e880467d9
commit 4eae7bedad
4 changed files with 34 additions and 15 deletions

26
src/Tool/Format.php Normal file
View File

@ -0,0 +1,26 @@
<?php
namespace SlotDb\Cli\Tool;
class Format
{
public static function formatValue(mixed $v): string
{
return match(true) {
is_array($v) =>
"[<fg=gray></><fg=green>".
join(",", array_map(Format::formatValue(...), $v)).
"</>]<fg=gray>(".count($v).")</>",
is_bool($v) =>
"<fg=cyan>".($v?"true":"false")."</>",
is_int($v) =>
"<fg=yellow>{$v}</>",
is_string($v) =>
"<fg=green>{$v}</>",
is_null($v) =>
"<fg=blue>null</>",
default =>
$v,
};
}
}