userPasswordHasher->isPasswordValid($user, $currentPassword); if ($currentHashedPassword === false) { throw new \InvalidArgumentException('The current password is invalid.'); } $user->setPassword($this->userPasswordHasher->hashPassword($user, $newPassword)); return $user; } }