-               $roles = [ 'ROLE_USER' ];
-
-               foreach($this->groups->toArray() as $group) {
-                       $roles[] = $group->getRole();
-               }
+               //Get the unique roles list by id
+               return array_unique(array_reduce(
+                       //Cast groups as array
+                       $this->groups->toArray(),
+                       //Reduce to an array of id => group tuples
+                       function ($array, $group) {
+                               $array[$group->getId()] = $group->getRole();
+                               return $array;
+                       },
+                       //Init with ROLE_USER
+                       //XXX: we assume that ROLE_USER has id 1 in database
+                       [ 1 => 'ROLE_USER' ]
+               ));
+       }