fix(base): readableBytes 补类型声明并修正拼接类型告警

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
kuaifan 2026-06-04 22:06:19 +00:00
parent 8e66f0bfb3
commit b595120d62

View File

@ -2818,14 +2818,17 @@ class Base
/**
* 字节转格式
* @param $bytes
* @param int|float $bytes
* @return string
*/
public static function readableBytes($bytes)
public static function readableBytes(int|float $bytes): string
{
$i = floor(log($bytes) / log(1024));
if ($bytes <= 0) {
return '0 B';
}
$i = (int) floor(log($bytes) / log(1024));
$sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
return sprintf('%.02F', $bytes / pow(1024, $i)) * 1 . ' ' . $sizes[$i];
return (string) ((float) sprintf('%.02F', $bytes / pow(1024, $i))) . ' ' . $sizes[$i];
}
/**