diff --git a/src/Adapter/User/UserTrait.php b/src/Adapter/User/UserTrait.php index 6c3a870..b18680c 100644 --- a/src/Adapter/User/UserTrait.php +++ b/src/Adapter/User/UserTrait.php @@ -6,6 +6,9 @@ use Pimcore\Model\DataObject\ClassDefinition\Data\Password; use Symfony\Component\Security\Core\User\UserInterface; +/** + * @method GroupInterface[]|null getGroups() + */ trait UserTrait { private array $roles = []; @@ -51,9 +54,8 @@ public function isEqualTo(UserInterface $user): bool public function getRoles(): array { $roles = $this->roles; - - /** @var GroupInterface $group */ - foreach ($this->getGroups() as $group) { + $groups = $this->getGroups() ?? []; + foreach ($groups as $group) { $groupRoles = $group->getRoles(); $roles[] = is_array($groupRoles) ? $groupRoles : []; } @@ -67,8 +69,8 @@ public function getRoles(): array public function getGroupNames(): array { $names = []; - /** @var GroupInterface $group */ - foreach ($this->getGroups() as $group) { + $groups = $this->getGroups() ?? []; + foreach ($groups as $group) { $names[] = $group->getName(); } @@ -82,7 +84,6 @@ public function hasGroupId(GroupInterface $userGroup): bool { $groups = $this->getGroups() ?? []; $groupIds = array_map(static function ($group) { - /* @var GroupInterface $group */ return $group->getId(); }, $groups); @@ -115,7 +116,6 @@ public function removeGroup(GroupInterface $userGroup): void { $groups = $this->getGroups() ?? []; $groupIds = array_map(static function ($group) { - /* @var GroupInterface $group */ return $group->getId(); }, $groups);