toHumanReadable(2); $bytes = $valueObject->toBytes(); // Color-code by size range $color = match (true) { $bytes < 1024 => ConsoleColor::WHITE, // Bytes $bytes < 1024 * 1024 => ConsoleColor::GREEN, // KB $bytes < 1024 * 1024 * 1024 => ConsoleColor::YELLOW, // MB $bytes < 1024 * 1024 * 1024 * 1024 => ConsoleColor::BRIGHT_YELLOW, // GB default => ConsoleColor::BRIGHT_RED, // TB+ }; return ConsoleStyle::create(color: $color)->apply($humanReadable); } public function formatHtml(object $valueObject, DisplayOptions $options): string { if (! $valueObject instanceof Byte) { return htmlspecialchars((string) $valueObject); } $humanReadable = $valueObject->toHumanReadable(2); $bytes = $valueObject->toBytes(); // CSS class based on size range $cssClass = match (true) { $bytes < 1024 => 'display-byte-size', $bytes < 1024 * 1024 => 'display-kb-size', $bytes < 1024 * 1024 * 1024 => 'display-mb-size', $bytes < 1024 * 1024 * 1024 * 1024 => 'display-gb-size', default => 'display-tb-size', }; return '' . htmlspecialchars($humanReadable) . ''; } }