mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Refactor SnmpResponse mapTable (#16238)
Replace previous code with a couple of foreach loops
This commit is contained in:
@@ -216,23 +216,19 @@ class SnmpResponse
|
|||||||
return new Collection;
|
return new Collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
return collect($this->values())
|
$data = [];
|
||||||
->map(function ($value, $oid) {
|
foreach ($this->values() as $key => $value) {
|
||||||
$parts = $this->getOidParts($oid);
|
$parts = $this->getOidParts($key);
|
||||||
$key = array_shift($parts);
|
$oid = array_shift($parts);
|
||||||
|
$data[implode('][', $parts)][$oid] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
$return = new Collection;
|
||||||
'_index' => implode('][', $parts),
|
foreach ($data as $index => $values) {
|
||||||
$key => $value,
|
$return->push(call_user_func($callback, $values, ...explode('][', (string) $index)));
|
||||||
];
|
}
|
||||||
})
|
|
||||||
->groupBy('_index')
|
|
||||||
->map(function ($values, $index) use ($callback) {
|
|
||||||
$values = array_merge(...$values);
|
|
||||||
unset($values['_index']);
|
|
||||||
|
|
||||||
return call_user_func($callback, $values, ...explode('][', (string) $index));
|
return $return;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user