/** * @param string[] $usernames * * @return ConfirmedMentionDto[] */ public function fetchMentions(array $usernames) { $mentions = $this->mentionRepository->getMentionsByUsernames($usernames); $confirmedMentionsDto = []; foreach ($mentions as $mention) { $confirmedMentionDto = new ConfirmedMentionDto(); $confirmedMentionDto->userId = $mention->getUserId(); $confirmedMentionDto->username = $mention->getUsername(); $confirmedMentionsDto[] = $confirmedMentionDto; } return $confirmedMentionsDto; }
/** * @param ConfirmedMentionDto[] $mentionsDto * * @return Mention[] */ public function map(array $mentionsDto) : array { $mentions = []; foreach ($mentionsDto as $mentionDto) { $mention = $this->mentionRepository->getByUserId($mentionDto->userId); if (null === $mention) { $mention = new Mention(); $mention->setUserId($mentionDto->userId); $mention->setUsername($mentionDto->username); } $mentions[] = $mention; } return $mentions; }