visitId(); /** @var Visit|null $visit */ $visit = $this->em->find(Visit::class, $visitId); if ($visit === null) { $this->logger->warning('Tried to notify mercure for visit with id "{visitId}", but it does not exist.', [ 'visitId' => $visitId, ]); return; } try { each($this->determineUpdatesForVisit($visit), fn (Update $update) => $this->hub->publish($update)); } catch (Throwable $e) { $this->logger->debug('Error while trying to notify mercure hub with new visit. {e}', [ 'e' => $e, ]); } } /** * @return Update[] */ private function determineUpdatesForVisit(Visit $visit): array { if ($visit->isOrphan()) { return [$this->updatesGenerator->newOrphanVisitUpdate($visit)]; } return [ $this->updatesGenerator->newShortUrlVisitUpdate($visit), $this->updatesGenerator->newVisitUpdate($visit), ]; } }