Ensure groups is an array before try to access them
Should fix:
Error: Undefined array key "groups" at /var/www/nextcloud/apps/workspace/lib/Service/UserService.php#65
Hi @solracsf :wave:
Thank you for your contribution :pray:
What is the case that causes this problem ?
Your proposal is not bad :
if (isset($space['groups']) && is_array($space['groups'])) {
// for
// if
}
But, I am not a big fan of nesting too deeply.
I try to follow the best practices : https://github.com/piotrplenik/clean-code-php?tab=readme-ov-file#avoid-nesting-too-deeply-and-return-early-part-1
What do you think of this rewrite ?
if (!isset($space['groups'])) {
throw new \Exception('The "groups" key is not present');
}
if (!is_array($space['groups'])) {
throw new \Exception('The "groups" key is not an array');
}
foreach ($this->groupManager->getUserGroups($user) as $group) {
if (in_array($group->getGID(), array_keys($space['groups']))) {
array_push($groups, $group->getGID());
}
}
Normally, I've solved the problem
Fine by me 🆗 Feel free to commit :-)
Nice ! Your PR @solracsf is updated and I applied my suggestions
We will test your PR as quickly as possible :wink:
backport is progressing to stable3.2