userRepo = $userRepo; $this->inviteRepo = $inviteRepo; $this->encoderFactory = $encoderFactory; } public function createUser(string $username, string $password, string $email, array $roles = self::DEFAULT_ROLES): User { $encodedPassword = $this->encoderFactory->getEncoder(User::class)->encodePassword($password, null); $user = new User( $username, $encodedPassword, $email, $roles ); $this->userRepo->add($user); return $user; } public function createUserByInviteCode(string $username, string $password, string $email, string $inviteCode, array $roles = self::DEFAULT_ROLES): User { /** @var Invite $invite */ if (null === $invite = $this->inviteRepo->findOneBy(['code' => $inviteCode, 'usedBy' => null])) { throw new InvalidInviteException(); } $user = $this->createUser($username, $password, $email,$roles); $invite->use($user); return $user; } }