/**
  * @param RegisterUserCommand $command
  *
  * @return User
  */
 protected function handleRegisterUser(RegisterUserCommand $command)
 {
     $username = new Username($command->username());
     $password = new Password($command->password());
     $user = $this->registerUserService->registerUser($username, $password);
     $this->userRepository->add($user);
     return $user;
 }
 /**
  * @param ChangeUsernameCommand $command
  *
  * @return User
  */
 protected function handleChangeUsername(ChangeUsernameCommand $command)
 {
     $userIdentifier = new UserIdentifier($command->userIdentifier());
     $newUsername = new Username($command->newUsername());
     $user = $this->userRepository->load($userIdentifier);
     $user->changeUsername($newUsername);
     return $user;
 }
 /**
  * @param ChangeUserPasswordCommand $command
  *
  * @return User
  */
 protected function handleChangeUserPassword(ChangeUserPasswordCommand $command)
 {
     $userIdentifier = new UserIdentifier($command->userIdentifier());
     $newPassword = new Password($command->newPassword());
     $hashedPassword = $this->passwordHashingService->hashPassword($newPassword);
     $user = $this->userRepository->load($userIdentifier);
     $user->changePassword($hashedPassword);
     return $user;
 }