public function changeUsername(User $user, string $newUsername): AuthenticationRecordInterface
    {
        /** @var AuthenticationRecordInterface $auth */
        $auth = $this->authenticationProvider->findByUserId($user->getId());

        if (!$auth) {
            throw new NoSuchUserException();
        }

        // check to see if already taken
        if ($otherAuth = $this->authenticationProvider->findByUsername($newUsername)) {
            if ($auth == $otherAuth) {
                return $auth;
            } else {
                throw new UsernameTakenException();
            }
        }

        $auth->setUsername($newUsername);
        $this->authenticationProvider->update($auth);

        return $auth;
    }
public function changeUsername(User $user, string $newUsername): AuthenticationRecordInterface
    {
        /** @var AuthenticationRecordInterface $auth */
        $auth = $this->authenticationProvider->findByUserId($user->getId());

        if (!$auth) {
            throw new NoSuchUserException();
        }

        // check to see if already taken
        if ($otherAuth = $this->authenticationProvider->findByUsername($newUsername)) {
            if ($auth == $otherAuth) {
                return $auth;
            } else {
                throw new UsernameTakenException();
            }
        }

        $auth->setUsername($newUsername);
        $this->authenticationProvider->update($auth);

        return $auth;
    }
public function changeUsername ( User $ user , string $ newUsername ) : AuthenticationRecordInterface { /** @var AuthenticationRecordInterface $auth */ $ auth = $ this -> authenticationProvider -> findByUserId ( $ user -> getId ( ) ) ; if ( ! $ auth ) { throw new NoSuchUserException ( ) ; } // check to see if already taken if ( $ otherAuth = $ this -> authenticationProvider -> findByUsername ( $ newUsername ) ) { if ( $ auth == $ otherAuth ) { return $ auth ; } else { throw new UsernameTakenException ( ) ; } } $ auth -> setUsername ( $ newUsername ) ; $ this -> authenticationProvider -> update ( $ auth ) ; return $ auth ; }
Change an auth record username given a user id and a new username.
Note - in this case username is email.

@param User $user
@param      $newUsername

@return AuthenticationRecordInterface
@throws NoSuchUserException Thrown when the user's authentication records couldn't be found
@throws UsernameTakenException
Change an auth record username given a user id and a new username . Note - in this case username is email .