fix: correctly determine file size and avoid type mismatch
This commit is contained in:
@@ -51,10 +51,14 @@ class AppRuntime implements RuntimeExtensionInterface
|
|||||||
|
|
||||||
public function formatBytes(int $bytes, ?int $precision = 2): string
|
public function formatBytes(int $bytes, ?int $precision = 2): string
|
||||||
{
|
{
|
||||||
$size = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
if (0 === $bytes) {
|
||||||
$factor = floor((strlen($bytes) - 1) / 3);
|
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
|
public function formatMoney(int $amount): string
|
||||||
|
|||||||
Reference in New Issue
Block a user