diff options
author | Simon Rettberg | 2022-01-18 15:26:47 +0100 |
---|---|---|
committer | Simon Rettberg | 2022-01-18 15:26:47 +0100 |
commit | 6caead054aeb647db1f46e19408f4754db101774 (patch) | |
tree | cf384eed6c1e8819f5cb37467cec8f8e6db1cc26 | |
parent | [statistics] Fix join ordering; renames and comments (diff) | |
download | slx-admin-6caead054aeb647db1f46e19408f4754db101774.tar.gz slx-admin-6caead054aeb647db1f46e19408f4754db101774.tar.xz slx-admin-6caead054aeb647db1f46e19408f4754db101774.zip |
[statistics] Fold constant
-rw-r--r-- | modules-available/statistics/inc/hardwareparser.inc.php | 10 |
1 files changed, 4 insertions, 6 deletions
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!! } |