fix: correctly determine file size and avoid type mismatch

This commit is contained in:
Björn Fromme
2026-03-16 12:03:00 +01:00
parent acb599b760
commit 4e05c94912
+7 -3
View File
@@ -51,10 +51,14 @@ class AppRuntime implements RuntimeExtensionInterface
public function formatBytes(int $bytes, ?int $precision = 2): string
{
$size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$factor = floor((strlen($bytes) - 1) / 3);
if (0 === $bytes) {
return '0 B';
}
return sprintf("%.{$precision}f", $bytes / (1024 ** $factor)).@$size[$factor];
$units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
$factor = (int) floor(log($bytes, 1024));
return sprintf("%.{$precision}f %s", $bytes / (1024 ** $factor), $units[$factor]);
}
public function formatMoney(int $amount): string