Skip to content

Commit

Permalink
Fix bug when you have an empty roles. (#200)
Browse files Browse the repository at this point in the history
* Fix bug when you have an empty roles.

* Use @method getGroup()
  • Loading branch information
blankse authored Aug 30, 2024
1 parent c6f2be2 commit befb64c
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/Adapter/User/UserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 : [];
}
Expand All @@ -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();
}

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit befb64c

Please sign in to comment.