mirror of
https://github.com/kuaifan/dootask.git
synced 2026-08-01 19:05:55 +00:00
fix(base): readableBytes 补类型声明并修正拼接类型告警
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
8e66f0bfb3
commit
b595120d62
@ -2818,14 +2818,17 @@ class Base
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 字节转格式
|
* 字节转格式
|
||||||
* @param $bytes
|
* @param int|float $bytes
|
||||||
* @return string
|
* @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'];
|
$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];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user