/**
  * @param $user
  * @param $system
  * @param $roleName
  * @param $locales
  *
  * @return mixed
  */
 private function addUserRole(UserInterface $user, $system, $roleName, $locales)
 {
     $role = $this->roleRepository->findOneBy(['system' => $system, 'name' => $roleName]);
     // create role when not exists
     if (!$role) {
         /** @var Role $role */
         $role = $this->roleRepository->createNew();
         $role->setSystem($system);
         $role->setName($roleName);
         $this->entityManager->persist($role);
     }
     // create new user roles
     $userRole = new UserRole();
     $userRole->setRole($role);
     $userRole->setUser($user);
     $locales = json_encode(array_values($locales));
     $userRole->setLocale($locales);
     $this->entityManager->persist($userRole);
 }