Refactor SnmpResponse mapTable (#16238)

Replace previous code with a couple of foreach loops
This commit is contained in:
Tony Murray
2024-07-22 21:23:10 -05:00
committed by GitHub
parent 7c8276052e
commit 55f603c30c

View File

@ -216,23 +216,19 @@ class SnmpResponse
return new Collection;
}
return collect($this->values())
->map(function ($value, $oid) {
$parts = $this->getOidParts($oid);
$key = array_shift($parts);
$data = [];
foreach ($this->values() as $key => $value) {
$parts = $this->getOidParts($key);
$oid = array_shift($parts);
$data[implode('][', $parts)][$oid] = $value;
}
return [
'_index' => implode('][', $parts),
$key => $value,
];
})
->groupBy('_index')
->map(function ($values, $index) use ($callback) {
$values = array_merge(...$values);
unset($values['_index']);
$return = new Collection;
foreach ($data as $index => $values) {
$return->push(call_user_func($callback, $values, ...explode('][', (string) $index)));
}
return call_user_func($callback, $values, ...explode('][', (string) $index));
});
return $return;
}
/**