diff --git a/module/Core/src/Visit/Entity/Visit.php b/module/Core/src/Visit/Entity/Visit.php index 9e8540bc5..2879ef66e 100644 --- a/module/Core/src/Visit/Entity/Visit.php +++ b/module/Core/src/Visit/Entity/Visit.php @@ -148,6 +148,15 @@ public function getType(): VisitType } public function jsonSerialize(): array + { + return $this->toArray(); + } + + /** + * @phpstan-type VisitedShortUrl array{shortCode: string, domain: string|null, shortUrl: string} + * @param (callable(ShortUrl $shortUrl): VisitedShortUrl)|null $visitedShortUrlToArray + */ + public function toArray(callable|null $visitedShortUrlToArray = null): array { $base = [ 'referer' => $this->referer, @@ -157,8 +166,11 @@ public function jsonSerialize(): array 'potentialBot' => $this->potentialBot, 'visitedUrl' => $this->visitedUrl, ]; - if (! $this->isOrphan()) { - return $base; + if ($this->shortUrl !== null) { + return $visitedShortUrlToArray === null ? $base : [ + ...$base, + 'visitedShortUrl' => $visitedShortUrlToArray($this->shortUrl), + ]; } return [