/**
  * @param Lang $lang
  * @param Logger $logger
  * @param User $newUserWrapper
  * @param Request $socketRequest
  * @return UserDAO
  */
 private function createNewUser(Lang $lang, Logger $logger, User $newUserWrapper, Request $socketRequest)
 {
     $user = UserDAO::create()->setChatId(1)->setDateRegister(DbQueryHelper::timestamp2date())->setRole(UserRoleEnum::USER)->setBanned(false)->setImprint(null);
     try {
         $user->save();
     } catch (\PDOException $e) {
         $logger->error("PDO Exception: " . $e->getMessage() . ': ' . $e->getTraceAsString(), [__METHOD__]);
     }
     $id = $user->getId();
     $guestName = $lang->getPhrase('Guest') . $id;
     if (PropertiesDAO::create()->getByUserName($guestName)->getName()) {
         $guestName = $lang->getPhrase('Guest') . ' ' . $id;
     }
     $properties = $user->getPropeties();
     $properties->setUserId($user->getId())->setName($guestName)->setSex(SexEnum::create(SexEnum::ANONYM))->setTim(TimEnum::create(TimEnum::ANY))->setBirthday(Rules::LOWEST_YEAR)->setOptions([PropertiesDAO::CENSOR => true])->setOnlineCount(0)->setMusicCount(0)->setWordsCount(0)->setRudeCount(0)->setKarma(0)->setMessagesCount(0)->setSubscription(true);
     try {
         $properties->save();
     } catch (\PDOException $e) {
         $logger->error("PDO Exception: " . $e->getTraceAsString(), [__CLASS__]);
     }
     if ($refUserId = $socketRequest->getCookie('refUserId')) {
         $ref = ReferralDAO::create()->getByUserId($user->getId(), $refUserId);
         if (!$ref) {
             $ref = ReferralDAO::create()->setUserId($user->getId())->setRefUserId($refUserId)->setDateRegister(DbQueryHelper::timestamp2date());
             $ref->save();
             $logger->info('Found referral userId ' . $refUserId . ' for guest userId ' . $user->getId());
         }
     }
     $logger->info("Created new user with id = {$id} for connectionId = {$newUserWrapper->getConnectionId()}", [__CLASS__]);
     return $user;
 }