summaryrefslogtreecommitdiffstats
path: root/modules-available/statistics/inc/hardwareparser.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/statistics/inc/hardwareparser.inc.php')
-rw-r--r--modules-available/statistics/inc/hardwareparser.inc.php26
1 files changed, 8 insertions, 18 deletions
diff --git a/modules-available/statistics/inc/hardwareparser.inc.php b/modules-available/statistics/inc/hardwareparser.inc.php
index 1c549976..428f7d55 100644
--- a/modules-available/statistics/inc/hardwareparser.inc.php
+++ b/modules-available/statistics/inc/hardwareparser.inc.php
@@ -38,8 +38,6 @@ class HardwareParser
/**
* Decode JEDEC ID to according manufacturer
- * @param string $string
- * @return string
*/
public static function decodeJedec(string $string): string
{
@@ -79,10 +77,7 @@ class HardwareParser
return $string;
}
- /**
- * @return ?string
- */
- private static function decodeBankAndId(array $out, bool $bankFirst)
+ private static function decodeBankAndId(array $out, bool $bankFirst): ?string
{
// 16bit encoding from DDR3+: lower byte is number of 0x7f bytes, upper byte is id within bank
$id = hexdec(str_replace(' ', '', $out[1]));
@@ -100,10 +95,7 @@ class HardwareParser
return self::lookupJedec($bank, $id);
}
- /**
- * @return ?string
- */
- private static function lookupJedec(int $bank, int $id)
+ private static function lookupJedec(int $bank, int $id): ?string
{
static $data = false;
if ($data === false) {
@@ -119,11 +111,9 @@ class HardwareParser
* base representation, meant for comparison. For example, Voltages are converted
* to Millivolts, Anything measured in [KMGT]Bytes (per second) to bytes, GHz to
* Hz, and so on.
- * @param string $key
- * @param string $value
* @return ?int value, or null if not numeric
*/
- private static function toNumeric(string $key, string $val)
+ private static function toNumeric(string $key, string $val): ?int
{
$key = strtolower($key);
// Normalize voltage to mV
@@ -208,7 +198,7 @@ class HardwareParser
* @param int $hwid hw global hw id
* @param string $pathId unique identifier for the local instance of this hw, e.q. PCI slot, /dev path, something that handles the case that there are multiple instances of the same hardware in one machine
* @param array $props KV-pairs of properties to write for this instance; can be empty
- * @return int
+ * @return int ID of mapping in DB
*/
private static function writeLocalHardwareData(string $uuid, int $hwid, string $pathId, array $props): int
{
@@ -330,7 +320,7 @@ class HardwareParser
* @param array $data Hardware info, deserialized assoc array.
* @return ?array id44mb and id45mb as calculated from given HDD data
*/
- public static function parseMachine(string $uuid, array $data)
+ public static function parseMachine(string $uuid, array $data): ?array
{
$version = $data['version'] ?? 0;
if ($version != 2) {
@@ -510,12 +500,12 @@ class HardwareParser
if (empty($dev['readlink'])) // This is the canonical entry name directly under /dev/, e.g. /dev/sda
continue;
// Use smartctl as the source of truth, lsblk as fallback if data is missing
- if (!isset($dev['smartctl'])) {
+ if (!isset($dev['smartctl']) || !is_array($dev['smartctl'])) {
$smart = [];
} else {
$smart =& $dev['smartctl'];
}
- if (!isset($dev['lsblk']['blockdevices'][0])) {
+ if (!isset($dev['lsblk']['blockdevices'][0]) || !is_array($dev['lsblk']['blockdevices'][0])) {
$lsblk = [];
} else {
$lsblk =& $dev['lsblk']['blockdevices'][0];
@@ -626,7 +616,7 @@ class HardwareParser
}
$table['unused'] = $size - $used;
$table['dev'] = $dev['readlink'];
- $table += self::propsFromArray($smart + ($lsblk ?? []),
+ $table += self::propsFromArray($smart + $lsblk,
'serial_number', 'firmware_version',
'interface_speed//current//string',
'smart_status//passed', 'temperature//current', 'temperature//min', 'temperature//max',