private function createAccountFromJSON(array $json) : Account { if ($this->accountService->hasAccountWithEmail($json['email'])) { return $this->accountService->getByEmail($json['email']); } else { $account = $this->accountService->createAccount($json['email'], GenerateRandomString::gen(12)); $profile = $account->getCurrentProfile(); $profile->setGender(Gender::createFromIntCode((int) $json['gender'])); $parameters = new EditPersonalParameters('fl', false, $json['username'] ?? '', $json['surname'] ?? '', $json['patronymic'] ?? '', $json['nickname'] ?? ''); $this->profileService->updatePersonalData($profile->getId(), $parameters); $this->profileService->setInterestingInThemes($profile->getId(), $json['interests']); if ($json['birthday']) { $this->profileService->setBirthday($profile->getId(), \DateTime::createFromFormat('Y-m-d', $json['birthday'])); } $avatarPath = sprintf("%s/%s", self::AVATAR_DIR, $json['avatar']); if (file_exists($avatarPath)) { list($width, $height) = getimagesize($avatarPath); if (!is_null($width) && !is_null($height)) { $size = min($width, $height); $parameters = new UploadImageParameters($avatarPath, new Point(0, 0), new Point($size, $size)); $this->profileService->uploadImage($profile->getId(), $parameters); } } return $account; } }