diff --git a/module/Core/src/Visit/Entity/Visit.php b/module/Core/src/Visit/Entity/Visit.php index 70733593f..b0fa9ffc3 100644 --- a/module/Core/src/Visit/Entity/Visit.php +++ b/module/Core/src/Visit/Entity/Visit.php @@ -150,6 +150,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, @@ -160,8 +169,11 @@ public function jsonSerialize(): array 'visitedUrl' => $this->visitedUrl, 'redirectUrl' => $this->redirectUrl, ]; - if (! $this->isOrphan()) { - return $base; + if ($this->shortUrl !== null) { + return $visitedShortUrlToArray === null ? $base : [ + ...$base, + 'visitedShortUrl' => $visitedShortUrlToArray($this->shortUrl), + ]; } return [