Cleanup value formatting code
This commit is contained in:
26
src/Tool/Format.php
Normal file
26
src/Tool/Format.php
Normal 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,
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user