public function update(UserInterface $user, $userData)
{
$this->validateForUpdate($user, $userData);
// encrypt password
if (!empty($userData['password'])) {
$userData['password'] = $this->hasher->make($userData['password']);
} else {
unset($userData['password']);
}
// resolve profileImage
if (!empty($userData['profileImgFile'])) {
$profileFile = $userData['profileImgFile'];
$userData['profileImageId'] = $this->imageHandler->updateUserProfileImage($user, $profileFile);
}
// resolve group
$groups = array_get($userData, 'groupId');
// email, displayName, introduction, password, status, rating
$userData = array_except($userData, ['groupId', 'profileImgFile']);
foreach ($userData as $key => $value) {
$user->{$key} = $value;
}
$user->save();
// join new group
if ($groups !== null) {
$changes = $user->groups()->sync($groups);
}
return $user;
}