From 3be02b60952b3fe6739d2423e24477540876e3c9 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 18 Jan 2022 15:26:47 +0100 Subject: [statistics] Fold constant --- modules-available/statistics/inc/hardwareparser.inc.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'modules-available/statistics/inc/hardwareparser.inc.php') diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php index 9b228c33..89edc8fd 100644 --- a/modules-available/statistics/inc/hardwareparser.inc.php +++ b/modules-available/statistics/inc/hardwareparser.inc.php @@ -6,8 +6,6 @@ class HardwareParser const SIZE_LOOKUP = ['T' => 1099511627776, 'G' => 1073741824, 'M' => 1048576, 'K' => 1024, '' => 1]; const SI_LOOKUP = ['T' => 1000000000000, 'G' => 1000000000, 'M' => 1000000, 'K' => 1000, '' => 1]; - const LOOKUP = ['T' => 1099511627776, 'G' => 1073741824, 'M' => 1048576, 'K' => 1024, '' => 1]; - /** * Convert/format size unit. Input string can be a size like * 8 GB or 1024 MB and will be converted according to passed parameters. @@ -22,16 +20,16 @@ class HardwareParser //error_log("Not size: $string"); return false; } - $val = (int)$out[1] * self::LOOKUP[strtoupper($out[2])]; - if (!array_key_exists($scale, self::LOOKUP)) { - foreach (self::LOOKUP as $k => $v) { + $val = (int)$out[1] * self::SIZE_LOOKUP[strtoupper($out[2])]; + if (!array_key_exists($scale, self::SIZE_LOOKUP)) { + foreach (self::SIZE_LOOKUP as $k => $v) { if ($k === '' || $val / 8 >= $v || abs($val - $v) < 50) { $scale = $k; break; } } } - $val = (int)round($val / self::LOOKUP[$scale]); + $val = (int)round($val / self::SIZE_LOOKUP[$scale]); if ($appendUnit) { $val .= ' ' . ($scale === '' ? 'Byte' : $scale . 'iB'); // NBSP!! } -- cgit v1.2.3-55-g7522