*/ class UserData extends Database { public function getByUserId(string $userId): ?UserDataEntity { /** @var ?UserDataEntity $userData */ $userData = $this ->where(['userId' => $userId]) ->findOne(); if ($userData) { return $userData; } $user = $this->entityManager ->getRepository('User') ->getById($userId); if (!$user) { return null; } $userData = $this->getNew(); $userData->set('userId', $userId); $this->save($userData, [ 'silent' => true, 'skipHooks' => true, ]); return $userData; } }